[squeak-dev] readFrom: vs readFromString:
lecteur at zogotounga.net
Tue Nov 1 16:45:17 UTC 2011
> That's it, I would change for something like
> readFromString: aString
> | aStream newInstance |
> aStream := aString readString.
> newInstance := self readFrom: aStream.
> aStream atEnd ifFalse: [FormatError raise].
I would propose to break this in two methods:
readFromString: aString onLeftOver: aBlock
| aStream newInstance |
aStream := aString readString.
newInstance := self readFrom: aStream.
aStream atEnd ifFalse: [aBlock value].
^ readFromString: aString onLeftOver: [FormatError raise]
This way we can handle cases where we do not care about trailing stuff,
without having to modify the string (which could be expensive)
More information about the Squeak-dev