--- a/PositionableStream.st Tue Feb 25 10:05:53 2003 +0100
+++ b/PositionableStream.st Tue Feb 25 11:15:21 2003 +0100
@@ -834,17 +834,37 @@
position
"return the read position"
- ^ position
+ ZeroPosition == 0 ifTrue:[
+ ^ self position0Based
+ ] ifFalse:[
+ ^ self position1Based
+ ].
!
-position:index
+position0Based
+ "return the read position 0-based"
+
+ ^ position - ZeroPosition
+!
+
+position0Based:index0Based
"set the read (or write) position"
- "/ FIX: allow positioning right after last element of stream
- "/ ((index > readLimit) or:[index < 0]) ifTrue: [^ self positionError].
+ ((index0Based > readLimit) or:[index0Based < 0]) ifTrue: [^ self positionError:index0Based].
+ position := index0Based + ZeroPosition
+!
+
+position1Based
+ "return the read position 1-based"
- ((index > (readLimit+1)) or:[index < ZeroPosition]) ifTrue: [^ self positionError:index].
- position := index
+ ^ position - ZeroPosition + 1
+!
+
+position1Based:index1Based
+ "set the read (or write) position"
+
+ ((index1Based > (readLimit+1)) or:[index1Based < 1]) ifTrue: [^ self positionError:index1Based].
+ position := index1Based - 1 + ZeroPosition
"
|s|
@@ -874,19 +894,45 @@
s nextPutAll:'abcdefg'.
s contents
"
-
!
-positionStartingAt0
- "return the read position, guaranteed to be zero based"
+position:newPos
+ "set the read (or write) position"
+
+ ZeroPosition == 0 ifTrue:[
+ ^ self position0Based:newPos
+ ] ifFalse:[
+ ^ self position1Based:newPos
+ ].
+
+ "
+ |s|
+
+ s := '1234567890' readStream.
+ s next:5.
+ s position:1.
+ s next:7.
+ "
- ^ position - self class zeroPosition
-!
+ "
+ |s|
+
+ s := '' writeStream.
+ s nextPutAll:'1234567890'.
+ s position:5.
+ s nextPutAll:'abcdefg'.
+ s contents
+ "
-positionStartingAt1
- "return the read position, guaranteed to be one-based"
+ "
+ |s|
- ^ self class zeroPosition == 1 ifTrue:[position] ifFalse:[position+1]
+ s := '' writeStream.
+ s nextPutAll:'1234567890'.
+ s position:0.
+ s nextPutAll:'abcdefg'.
+ s contents
+ "
!
reset
@@ -1148,7 +1194,7 @@
!PositionableStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.120 2003-02-25 09:05:53 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.121 2003-02-25 10:14:58 cg Exp $'
! !
PositionableStream initialize!