On Tue, Feb 9, 2016 at 8:29 PM, Leonardo Silva <leonardo.humberto@gmail.com> wrote:
Hi,
I'd like to skip to a specific position in a stream based on a substring. I got the following example that works for a single character:
stream := 'abcdef' readStream. stream skipTo: $e. stream next. -â $f
But it does not work for substrings. I'd like to have something like:
stream := 'abcdef' readStream. stream skipTo: 'de'. stream next. -â "But this returns nil"
Do you know how to do it?
Thanks,
Leonardo
I see there is only one implementer PositionableStream skipTo: anObject "Set the access position of the receiver to be past the next occurrence of anObject. Answer whether anObject is found." [self atEnd] whileFalse: [self next = anObject ifTrue: [^true]]. ^false first btw, did you debug into this method to understand why it doesn't work with strings? It would help observation to change the method line this... whileFalse: [(x:=self next) = anObject ifTrue: [^true]]. I don't see anything useful in the superclass, but I see PositionableStream>>positionOfSubCollection: Short answer is that you skipTo: wont work with strings since the stream elements are not Strings, they are Characters. You will need to create your own method for this, perhaps named skipToSubCollection: cheers -ben