Bug 38371

GemStone/S

6.2.3, 6.2.2, 6.2.1, 6.2, 6.1.6, 6.1.5, 6.1.x, 6.0.x, 5.1.5

All

6.3

throughAll: incorrect results for some arguments

For some receiver and argument combinations, the method
PositionableStream>>thoughAll: may fail to match a valid argument.

Workaround

category: 'Accessing'
method: PositionableStream
throughAll: matchCollection

"Returns a collection of objects from the receiver up to and including the
sequence of objects in the argument 'matchCollection', leaving the stream
positioned after the sequence.  If the sequence of objects is not found, this
returns the remaining contents of the receiver and leaves me positioned
at my end."

| numMatched numToMatch result  |

numMatched := 0.
result := itsCollection species new.
numToMatch := matchCollection size.
[self atEnd _or: [numMatched = numToMatch]]
     whileFalse:
           [self next = (matchCollection at: numMatched + 1)
                ifTrue: [numMatched := numMatched + 1]
          ifFalse: [position := position - numMatched - 1.
                        result add: self next.
                        numMatched := 0]
].

"add matched or partially matched chars"
position := position - numMatched.
numMatched timesRepeat: [result add: self next].

^ result.
%


Last updated: 5/15/08