Administrator
|
Relevant to Pharo?
From http://forum.world.st/ByteArray-at-put-tp4955848.html : Bert Freudenberg wrote > On 26 April 2018 at 11:28, marcel.taeumel < > Marcel.Taeumel@ > > wrote: > >> Hi, there. >> >> I cannot put a ByteString into a ByteArray via a WriteStream anymore: >> >> | s | >> s := WriteStream on: ByteArray new. >> s nextPutAll: 'hello'. >> >> You need to do: >> >> | s | >> s := WriteStream on: ByteArray new. >> s nextPutAll: 'hello' asByteArray. >> >> This breaks code. >> >> Best, >> Marcel >> > > Technically this is an expected error - you simply cannot put Characters > (the elements of a String) into a ByteArray. However, for convenience we > do > support copying Strings into ByteArrays in various places, including > WriteStream>>nextPutAll:. > > However, the test in WriteStream>>nextPutAll: is too strict. It needs to > be > "collection class isBits" instead of "collection isString". This makes the > code actually match its comment: > > WriteStream>>nextPutAll: aCollection > > | newEnd | > (collection class == aCollection class > or: [ collection class isBits > and: [ aCollection isString > and: [ collection class format = aCollection class format ] ] ]) "Let > Strings with the same field size as collection take the quick route too." > ifFalse: [ ^ super nextPutAll: aCollection ]. > > newEnd := position + aCollection size. > newEnd > writeLimit ifTrue: > [self growTo: newEnd + 10]. > > collection replaceFrom: position+1 to: newEnd with: aCollection > startingAt: 1. > position := newEnd. > ^aCollection > > With that change your example works. I think this was the original intent > of the code. > > Fixed in Collections-bf.787 > > - Bert - ----- Cheers, Sean -- Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html
Cheers,
Sean |
> On 26 Apr 2018, at 15:21, Sean P. DeNigris <[hidden email]> wrote: > > Relevant to Pharo? > > From http://forum.world.st/ByteArray-at-put-tp4955848.html : We don't (want to) mix binary and character collections or streams. Going from one to the other is called encoding and decoding, it has to be done while being conscious of which encoding you are using. Sending #asByteArray to a String or #asString to a ByteArray is dangerous, lazy and wrong (in most cases), especially in an international context. > Bert Freudenberg wrote >> On 26 April 2018 at 11:28, marcel.taeumel < > >> Marcel.Taeumel@ > >> > wrote: >> >>> Hi, there. >>> >>> I cannot put a ByteString into a ByteArray via a WriteStream anymore: >>> >>> | s | >>> s := WriteStream on: ByteArray new. >>> s nextPutAll: 'hello'. >>> >>> You need to do: >>> >>> | s | >>> s := WriteStream on: ByteArray new. >>> s nextPutAll: 'hello' asByteArray. >>> >>> This breaks code. >>> >>> Best, >>> Marcel >>> >> >> Technically this is an expected error - you simply cannot put Characters >> (the elements of a String) into a ByteArray. However, for convenience we >> do >> support copying Strings into ByteArrays in various places, including >> WriteStream>>nextPutAll:. >> >> However, the test in WriteStream>>nextPutAll: is too strict. It needs to >> be >> "collection class isBits" instead of "collection isString". This makes the >> code actually match its comment: >> >> WriteStream>>nextPutAll: aCollection >> >> | newEnd | >> (collection class == aCollection class >> or: [ collection class isBits >> and: [ aCollection isString >> and: [ collection class format = aCollection class format ] ] ]) "Let >> Strings with the same field size as collection take the quick route too." >> ifFalse: [ ^ super nextPutAll: aCollection ]. >> >> newEnd := position + aCollection size. >> newEnd > writeLimit ifTrue: >> [self growTo: newEnd + 10]. >> >> collection replaceFrom: position+1 to: newEnd with: aCollection >> startingAt: 1. >> position := newEnd. >> ^aCollection >> >> With that change your example works. I think this was the original intent >> of the code. >> >> Fixed in Collections-bf.787 >> >> - Bert - > > > > > > ----- > Cheers, > Sean > -- > Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html > |
Sven Van Caekenberghe <[hidden email]> wrote:
> > >> On 26 Apr 2018, at 15:21, Sean P. DeNigris >> <[hidden email]> wrote: >> >> Relevant to Pharo? >> >> From http://forum.world.st/ByteArray-at-put-tp4955848.html : > > We don't (want to) mix binary and character collections or streams. Going > from one to the other is called encoding and decoding, it has to be done > while being conscious of which encoding you are using. Sending > #asByteArray to a String or #asString to a ByteArray is dangerous, lazy > and wrong (in most cases), especially in an international context. How do we capture these kinds of decisions? This is crucial information for people trying to migrate to Pharo. Stephan |
> On 26 Apr 2018, at 20:19, Stephan Eggermont <[hidden email]> wrote: > > Sven Van Caekenberghe <[hidden email]> wrote: >> >> >>> On 26 Apr 2018, at 15:21, Sean P. DeNigris >>> <[hidden email]> wrote: >>> >>> Relevant to Pharo? >>> >>> From http://forum.world.st/ByteArray-at-put-tp4955848.html : >> >> We don't (want to) mix binary and character collections or streams. Going >> from one to the other is called encoding and decoding, it has to be done >> while being conscious of which encoding you are using. Sending >> #asByteArray to a String or #asString to a ByteArray is dangerous, lazy >> and wrong (in most cases), especially in an international context. > > How do we capture these kinds of decisions? This is crucial information for > people trying to migrate to Pharo. I don't know, so much to do. But in this particular case, doing it the lazy way is really a bug. > Stephan |
Free forum by Nabble | Edit this page |