[Pharo-project] WriteStream

Henrik Johansen henrik.s.johansen at veloxit.no
Fri Nov 5 12:47:38 CET 2010


IMHO, asString should not be sent at all :)
If you want a WriteStream on a Texts string, provide the texts string as
an argument
This will likely not work as you want though, as there's no become of
the underlying collection of the WriteStream when you attempt to write
past the capacity of the original in Squeak/Pharo.
So you'd probably end up wondering why your text does not display
everything you wrote using the WriteStream.

A good suggestion would be to treat Text objects wrt the string they
represent as immutable objects.

Cheers,
Henry

Den 05.11.2010 10:28, skrev Benjamin:
>
> On Nov 5, 2010, at 10:30 AM, Igor Stasenko wrote:
>
>> On 5 November 2010 11:20, Benjamin
>> <benjamin.vanryseghem.pharo at gmail.com> wrote:
>>> Hello everyone,
>>> I thing, there is a bug in WriteStream, but i'm not sure.
>>> When I look at this code, I guess aString is not always a String, and
>>> yesterday, I had a Text send to this method, which raised a DNU error.
>>> (in blue is what I have change to make it work in my case)
>>> WriteStream>>nextChunkPut: aString
>>> "Append the argument, aString, to the receiver, doubling embedded
>>> terminators."
>>>
>>> | i remainder terminator |
>>> terminator := $!.
>>> remainder := aString asString.
>>> [(i := remainder indexOf: terminator) = 0] whileFalse:
>>> [self nextPutAll: (remainder copyFrom: 1 to: i).
>>> self nextPut: terminator.  "double imbedded terminators"
>>> remainder := remainder copyFrom: i+1 to: remainder size].
>>> self nextPutAll: remainder.
>>> aString asString includesUnifiedCharacter ifTrue: [
>>> self nextPut: terminator.
>>> self nextPutAll: ']lang['.
>>> aString asString writeLeadingCharRunsOn: self.
>>> ].
>>> self nextPut: terminator.
>>>
>>>
>>> Is that a bug ?
>>>
>> yes.
>>
>> I'd say the whole method is a bug. Repeating
>> aString asString multiple times in code cries out of loud that it
>> could be anything but not right :)
>
> I think so ^^
>
> I'll create a bug entry
> Ben
>
>>
>>
>>> Regards,
>>> Ben
>>
>>
>>
>> -- 
>> Best regards,
>> Igor Stasenko AKA sig.
>>
>
>
>




More information about the Pharo-project mailing list