[fix] TextStream
Boris Gaertner
Boris.Gaertner at gmx.net
Sun Jan 5 18:46:26 UTC 2003
>
> It seems like there jumped an obsolete "string" into the nextPutAll:
method of
> TextStream. Commenting it out gets it to work again.
>
> (umm.. im by no means experienced squeaker, maybe you should test this
before
> believing me)
>
> My test:
> |w|
> w _ TextStream on: ''.
> w nextPutAll: 'hola'. w nextPutAll: ' chica'.
> w contents
>
> regards,
>
Nick,
TextStreams are designed to stream not over an instance of String, but
over an instance of Text. An instance of Text has two components:
a string and a run array that keeps style attributes for every single
character of the string.
You should write
|w|
w _ TextStream on: Text new.
w nextPutAll: 'hola'. w nextPutAll: ' chica'.
w contents
This works. To assemble a string, you can
use a WriteStream.
The message string in TextStream>>nextPutAll:
is, as far as I understand, an optimization: Without it, the replacement
would be performed on the text. It is however sufficient to perform
the replacement on the string. Removal of the message will do
no harm, it will only extent the replacement operation to the
run array.
Here is an example that shows what you can do with
TextStreams: (execute it in a workspace)
</example>
| ts |
ts := TextStream on: (Text new: 100).
ts nextPutAll: 'Class ';
withAttribute: TextEmphasis bold
do: [ts nextPutAll: 'TextStream'];
cr.
ts nextPutAll: 'This class is used to create ';
withAttributes: (Set with: TextEmphasis bold with: TextEmphasis
underlined)
do: [ts nextPutAll: 'stylished text.'];
cr;
withAttribute: TextEmphasis italic
do: [ts nextPutAll: 'Stylished text'];
withAttribute: TextEmphasis normal
do: [ts nextPutAll: ' has display properties like '];
withAttribute: TextEmphasis bold
do: [ts nextPutAll: 'bold '];
withAttribute: TextEmphasis italic
do: [ts nextPutAll: 'italic '];
withAttribute: TextEmphasis struckOut
do: [ts nextPutAll: 'struck out '];
cr.
(Workspace new contents: ts contents)
openLabel: 'TextStreams are powerful'
</example>
So, I am still not certain whether or not we should remove the
message #string.
Greetings, Boris
More information about the Squeak-dev
mailing list
|