Mariano,
What would be wrong with something more elegant, like
consumeWhitespace
"Strip whitespaces from the input stream."
[ readStream atEnd not and: [ readStream peek isSeparator ] ]
whileTrue: [
readStream next ]
?
In my book #peek, which means a one-element pushback buffer, is a whole lot
less of a requirement that a general #position[:] interface which actually
assumes that all contents is in memory, a contradiction to the concept of
streaming.
Maybe these uglier versions are more efficient, but who can say for sure they
are correct ?
;-)
Sven
On 06 Sep 2012, at 10:26, Mariano Martinez Peck <[email protected]> wrote:
> Hi guys. I found a problem when exporting/importing chunks with
> MultiByteBinaryOrTextStream and I think #skipSeparators is wrong.
> The code is:
>
> MultiByteBinaryOrTextStream >> skipSeparators
>
> [self atEnd] whileFalse: [
> self basicNext isSeparator ifFalse: [
> ^ self position: self position - 1]]
>
> Problem is that the position is not save, as it is done in
>
> MultiByteFileStream >> skipSeparators
>
> | state character |
> [
> state := converter saveStateOf: self.
> (character := self next)
> ifNil: [ false ]
> ifNotNil: [ character isSeparator ] ] whileTrue.
> character ifNotNil: [
> converter restoreStateOf: self with: state ]
>
>
> If I copy the implementation from MultiByteFileStream to
> MultiByteBinaryOrTextStream, my tests work as expected.
> But I am not a stream expert. So, what do you think? is this change correct?
>
> Thanks,
>
> --
> Mariano
> http://marianopeck.wordpress.com
--
Sven Van Caekenberghe
http://stfx.eu
Smalltalk is the Red Pill