Skip to content

Commit 99e2e1d

Browse files
committed
Add some methods from PositionableStream used by Tonel (ref #208)
(cherry-picked from commit 5cbf1d51680dbd029b87f476ab18b50d4159b343)
1 parent ef321ed commit 99e2e1d

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
positioning
2+
match: subCollection
3+
"Set the access position of the receiver to be past the next occurrence of the subCollection. Answer whether subCollection is found. No wildcards, and case does matter."
4+
5+
| pattern startMatch |
6+
pattern := ReadStream on: subCollection.
7+
startMatch := nil.
8+
[pattern atEnd] whileFalse:
9+
[self atEnd ifTrue: [^ false].
10+
(self next) = (pattern next)
11+
ifTrue: [pattern position = 1 ifTrue: [startMatch := self position]]
12+
ifFalse: [pattern position: 0.
13+
startMatch ifNotNil: [
14+
self position: startMatch.
15+
startMatch := nil]]].
16+
^ true
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
accessing
2+
upToAll: aCollection
3+
"Answer a subcollection from the current access position to the occurrence (if any, but not inclusive) of aCollection. If aCollection is not in the stream, answer the entire rest of the stream."
4+
5+
| startPos endMatch result |
6+
startPos := self position.
7+
(self match: aCollection)
8+
ifTrue: [endMatch := self position.
9+
self position: startPos.
10+
result := self upToPosition: endMatch - aCollection size.
11+
self position: endMatch.
12+
^ result]
13+
ifFalse: [self position: startPos.
14+
^ self upToEnd]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
accessing
2+
upToPosition: anInteger
3+
"Answer a subcollection containing items starting from the current position and ending including the given position. Usefully different to #next: in that in the case of MultiByteFileStream, and perhaps others, positions measure in terms of encoded items, while #next: convention is to name a number of items, independent of their encoding in the underlying buffer."
4+
^ self next: anInteger - self position

src/FS-AnsiStreams.package/TPositionableStream.trait/methodProperties.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@
44
"instance" : {
55
"back" : "jr 3/7/2017 17:08",
66
"errorCantGoBack" : "jr 3/7/2017 17:03",
7-
"reset" : "jr 6/7/2017 13:03" } }
7+
"match:" : "jr 12/9/2018 19:43",
8+
"reset" : "jr 6/7/2017 13:03",
9+
"upToAll:" : "jr 12/9/2018 19:43",
10+
"upToPosition:" : "jr 12/9/2018 19:43" } }

0 commit comments

Comments
 (0)