PositionableStream.st
author penk
Tue, 14 Dec 2004 14:14:09 +0100
changeset 8657 1df84e8daa15
parent 8443 7bc4348c059e
child 9003 baa2a9409c9d
permissions -rw-r--r--
care for nil suspendedContext in description
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
5393
7e2230bd4bad moved some stuff to superclass
Claus Gittinger <cg@exept.de>
parents: 5308
diff changeset
    13
"{ Package: 'stx:libbasic' }"
7e2230bd4bad moved some stuff to superclass
Claus Gittinger <cg@exept.de>
parents: 5308
diff changeset
    14
57
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    15
PeekableStream subclass:#PositionableStream
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
    16
	instanceVariableNames:'collection position readLimit writeLimit'
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8363
diff changeset
    17
	classVariableNames:'ZeroPosition InvalidPositionErrorSignal'
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
    18
	poolDictionaries:''
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
    19
	category:'Streams'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
1897
22d1ce9b62a4 fixes for packageQuery
Claus Gittinger <cg@exept.de>
parents: 1489
diff changeset
    22
!PositionableStream class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    23
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    25
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    26
 COPYRIGHT (c) 1989 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
    27
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    28
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
!
10
claus
parents: 5
diff changeset
    37
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    39
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
    Instances of PositionableStream allow positioning the read pointer.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    41
    The PositionableStream class also adds methods for source-chunk reading
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    42
    and writing, and for filing-in/out of source code.
3249
8401c3e42165 checkin to force re-checkout.
Claus Gittinger <cg@exept.de>
parents: 3184
diff changeset
    43
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    44
    This is an abstract class.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
    45
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
    46
    Compatibility Notice:
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
    47
       For historical reasons, ST/X starts with a 1-position (i.e. as in collections),
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
    48
       while ST-80 uses 0-based postions for streams and 1-based positions for collections.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
    49
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
    50
    THIS CERTAINLY IS BAD.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
    51
    To allow for portable code, this method can be asked to return the initial position.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
    52
    (for code, which ought to execute under other systems, use:
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
    53
       posZero := (PositionableStream class respondsTo:#zeroPosition) 
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
    54
		       ifTrue:[PositionableStream zeroPosition]
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
    55
		       ifFalse:[0] 
5228
637a1a93b740 comments
Claus Gittinger <cg@exept.de>
parents: 5223
diff changeset
    56
    Please use this query for ST/X programs - we will eventually switch to a 0-based
637a1a93b740 comments
Claus Gittinger <cg@exept.de>
parents: 5223
diff changeset
    57
    indexing scheme, and your programs should be prepared for that.
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
    58
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
    59
    [author:]
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
    60
	Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    61
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    62
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    63
1897
22d1ce9b62a4 fixes for packageQuery
Claus Gittinger <cg@exept.de>
parents: 1489
diff changeset
    64
!PositionableStream class methodsFor:'initialization'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    65
10
claus
parents: 5
diff changeset
    66
initialize
7363
721c2a72449a stream position now 0-based
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
    67
    ZeroPosition := 0.        "/ changed with stx rel5.1
721c2a72449a stream position now 0-based
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
    68
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8363
diff changeset
    69
    InvalidPositionErrorSignal isNil ifTrue:[
7092
630807cd320f Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents: 7054
diff changeset
    70
        InvalidPositionErrorSignal := PositionOutOfBoundsError.
630807cd320f Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents: 7054
diff changeset
    71
        InvalidPositionErrorSignal notifierString:'position out of bounds: '.
10
claus
parents: 5
diff changeset
    72
    ]
claus
parents: 5
diff changeset
    73
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    74
1897
22d1ce9b62a4 fixes for packageQuery
Claus Gittinger <cg@exept.de>
parents: 1489
diff changeset
    75
!PositionableStream class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    76
a27a279701f8 Initial revision
claus
parents:
diff changeset
    77
on:aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
    78
    "return a new PositionableStream streaming on aCollection"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    79
a27a279701f8 Initial revision
claus
parents:
diff changeset
    80
    ^ (self basicNew) on:aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
    81
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    82
a27a279701f8 Initial revision
claus
parents:
diff changeset
    83
on:aCollection from:first to:last
a27a279701f8 Initial revision
claus
parents:
diff changeset
    84
    "return a new PositionableStream streaming on aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
    85
     from first to last"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    86
369
claus
parents: 362
diff changeset
    87
    ^ (self basicNew) on:aCollection from:first to:last
57
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    88
!
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    89
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    90
with:aCollection
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    91
    "return a new PositionableStream streaming on aCollection,
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    92
     the stream is positioned to the end of the collection."
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    93
362
claus
parents: 360
diff changeset
    94
    ^ (self basicNew) with:aCollection
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    95
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
    96
3032
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
    97
!PositionableStream class methodsFor:'Signal constants'!
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
    98
5223
06cf79da1d4a added currentFileInDirectory query
tm
parents: 5098
diff changeset
    99
currentFileInDirectoryQuerySignal
06cf79da1d4a added currentFileInDirectory query
tm
parents: 5098
diff changeset
   100
    "return the querySignal, which can be used to ask for the current directory
5228
637a1a93b740 comments
Claus Gittinger <cg@exept.de>
parents: 5223
diff changeset
   101
     during a fileIn (that is the directory where the filed-in file resides),
637a1a93b740 comments
Claus Gittinger <cg@exept.de>
parents: 5223
diff changeset
   102
     and in a fileBrowsers doIt.
637a1a93b740 comments
Claus Gittinger <cg@exept.de>
parents: 5223
diff changeset
   103
     Using this, allows for the loaded code or doIts to ask for the fileBrowsers
637a1a93b740 comments
Claus Gittinger <cg@exept.de>
parents: 5223
diff changeset
   104
     current directory, by asking this querySignal (which is nice sometimes)."
5223
06cf79da1d4a added currentFileInDirectory query
tm
parents: 5098
diff changeset
   105
06cf79da1d4a added currentFileInDirectory query
tm
parents: 5098
diff changeset
   106
    ^ CurrentFileInDirectoryQuerySignal
06cf79da1d4a added currentFileInDirectory query
tm
parents: 5098
diff changeset
   107
!
06cf79da1d4a added currentFileInDirectory query
tm
parents: 5098
diff changeset
   108
3032
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   109
invalidPositionErrorSignal
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   110
    "return the signal raised if positioning is attempted to an
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   111
     invalid position (i.e. before the begin of the stream or after
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   112
     the end)"
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   113
8320
229adaeaf183 Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents: 8318
diff changeset
   114
    ^ PositionOutOfBoundsError
3032
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   115
! !
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   116
1897
22d1ce9b62a4 fixes for packageQuery
Claus Gittinger <cg@exept.de>
parents: 1489
diff changeset
   117
!PositionableStream class methodsFor:'constants'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   118
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   119
zeroPosition
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   120
    "return the number, which marks the initial position.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   121
     Compatibility Notice:
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   122
	For historical reasons, ST/X starts with a 1-position (i.e. as in collections),
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   123
	while ST-80 uses 0-based postions for streams and 1-based positions for collections.
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   124
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   125
     THIS CERTAINLY IS BAD.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   126
     To allow for portable code, this method can be asked to return the initial position.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   127
     (for code, which ought to execute under other systems, use:
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   128
	posZero := (PositionableStream class respondsTo:#zeroPosition) 
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   129
			ifTrue:[PositionableStream zeroPosition]
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   130
			ifFalse:[0] 
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   131
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   132
     Be prepared for this to be changed to return 0 as other ST's do.
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   133
	"
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   134
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   135
    ^ ZeroPosition
360
claus
parents: 329
diff changeset
   136
! !
claus
parents: 329
diff changeset
   137
6777
5efddf5358b2 currentFileInDirectory query
Claus Gittinger <cg@exept.de>
parents: 6707
diff changeset
   138
!PositionableStream class methodsFor:'queries'!
5efddf5358b2 currentFileInDirectory query
Claus Gittinger <cg@exept.de>
parents: 6707
diff changeset
   139
5efddf5358b2 currentFileInDirectory query
Claus Gittinger <cg@exept.de>
parents: 6707
diff changeset
   140
currentFileInDirectory
5efddf5358b2 currentFileInDirectory query
Claus Gittinger <cg@exept.de>
parents: 6707
diff changeset
   141
    "during a fileIn (if a script), the script can ask for the current directory"
5efddf5358b2 currentFileInDirectory query
Claus Gittinger <cg@exept.de>
parents: 6707
diff changeset
   142
5efddf5358b2 currentFileInDirectory query
Claus Gittinger <cg@exept.de>
parents: 6707
diff changeset
   143
    ^ CurrentFileInDirectoryQuerySignal query
5efddf5358b2 currentFileInDirectory query
Claus Gittinger <cg@exept.de>
parents: 6707
diff changeset
   144
! !
5efddf5358b2 currentFileInDirectory query
Claus Gittinger <cg@exept.de>
parents: 6707
diff changeset
   145
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7226
diff changeset
   146
!PositionableStream methodsFor:'Compatibility-Dolphin'!
6413
dc8d492a39ff dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6361
diff changeset
   147
dc8d492a39ff dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6361
diff changeset
   148
endChunk
dc8d492a39ff dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6361
diff changeset
   149
    self nextPutChunkSeparator
dc8d492a39ff dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6361
diff changeset
   150
! !
dc8d492a39ff dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6361
diff changeset
   151
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   152
!PositionableStream methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   153
7686
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7619
diff changeset
   154
collection
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7619
diff changeset
   155
    ^ collection
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7619
diff changeset
   156
!
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7619
diff changeset
   157
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   158
contents
a27a279701f8 Initial revision
claus
parents:
diff changeset
   159
    "return the entire contents of the stream"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   160
a27a279701f8 Initial revision
claus
parents:
diff changeset
   161
    ^ collection
a27a279701f8 Initial revision
claus
parents:
diff changeset
   162
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   163
a27a279701f8 Initial revision
claus
parents:
diff changeset
   164
peek
a27a279701f8 Initial revision
claus
parents:
diff changeset
   165
    "look ahead for and return the next element"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   166
a27a279701f8 Initial revision
claus
parents:
diff changeset
   167
    |peekObject|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   168
a27a279701f8 Initial revision
claus
parents:
diff changeset
   169
    peekObject := self next.
10
claus
parents: 5
diff changeset
   170
    self backStep.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   171
    ^ peekObject
a27a279701f8 Initial revision
claus
parents:
diff changeset
   172
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   173
2432
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   174
peekForAll:aCollection
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   175
    "return true and advance if the next elements are the same
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   176
     as aCollection. 
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   177
     otherwise stay and let the position unchanged"
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   178
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   179
    |oldPos|
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   180
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   181
    oldPos := self position.
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   182
    (self next:(aCollection size)) = aCollection ifTrue:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   183
	^ true
2432
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   184
    ].
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   185
    self position:oldPos.
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   186
    ^ false
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   187
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   188
    "Created: 1.3.1997 / 15:11:25 / cg"
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   189
!
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   190
3905
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   191
readLimit
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   192
    "return the read-limit; thats the position at which EOF is returned"
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   193
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   194
    ^ readLimit
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   195
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   196
    "Created: / 30.10.1998 / 16:47:04 / cg"
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   197
!
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   198
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   199
readLimit:aNumber
369
claus
parents: 362
diff changeset
   200
    "set the read-limit; thats the position at which EOF is returned"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   201
a27a279701f8 Initial revision
claus
parents:
diff changeset
   202
    readLimit := aNumber
369
claus
parents: 362
diff changeset
   203
!
claus
parents: 362
diff changeset
   204
claus
parents: 362
diff changeset
   205
writeLimit:aNumber
claus
parents: 362
diff changeset
   206
    "set the writeLimit; thats the position after which writing is prohibited"
claus
parents: 362
diff changeset
   207
claus
parents: 362
diff changeset
   208
    writeLimit := aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   209
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   210
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   211
!PositionableStream methodsFor:'positioning'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   212
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   213
backStep
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   214
    "move backward read position by one"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   215
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   216
    self position:(self position - 1)
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   217
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   218
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   219
position
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   220
    "return the read position"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   221
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   222
    ZeroPosition == 0 ifTrue:[
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   223
        ^ self position0Based
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   224
    ] ifFalse:[
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   225
        ^ self position1Based
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   226
    ].
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   227
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   228
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   229
position0Based
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   230
    "return the read position 0-based"
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   231
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   232
    ^ position - ZeroPosition
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   233
!
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   234
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   235
position0Based:index0Based
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   236
    "set the read (or write) position"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   237
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   238
    ((index0Based > readLimit) or:[index0Based < 0]) ifTrue: [^ self positionError:index0Based].
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   239
    position := index0Based + ZeroPosition
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   240
!
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   241
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   242
position1Based
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   243
    "return the read position 1-based"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   244
7053
13e04c48e23c prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7052
diff changeset
   245
    ^ self position0Based + 1
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   246
!
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   247
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   248
position1Based:index1Based
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   249
    "set the read (or write) position"
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   250
7053
13e04c48e23c prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7052
diff changeset
   251
    self position0Based:(index1Based - 1)
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   252
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   253
    "
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   254
     |s|
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   255
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   256
     s := '1234567890' readStream.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   257
     s next:5.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   258
     s position:1.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   259
     s next:7.       
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   260
    "
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   261
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   262
    "
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   263
     |s|
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   264
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   265
     s := '' writeStream.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   266
     s nextPutAll:'1234567890'.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   267
     s position:5.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   268
     s nextPutAll:'abcdefg'.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   269
     s contents 
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   270
    "
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   271
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   272
    "
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   273
     |s|
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   274
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   275
     s := '' writeStream.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   276
     s nextPutAll:'1234567890'.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   277
     s position:0.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   278
     s nextPutAll:'abcdefg'.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   279
     s contents 
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   280
    "
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   281
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   282
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   283
position:newPos
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   284
    "set the read (or write) position"
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   285
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   286
    ZeroPosition == 0 ifTrue:[
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   287
        ^ self position0Based:newPos
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   288
    ] ifFalse:[
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   289
        ^ self position1Based:newPos
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   290
    ].
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   291
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   292
    "
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   293
     |s|
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   294
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   295
     s := '1234567890' readStream.
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   296
     s next:5.
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   297
     s position:1.
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   298
     s next:7.       
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   299
    "
6626
f7b08d6bee3f #positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents: 6538
diff changeset
   300
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   301
    "
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   302
     |s|
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   303
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   304
     s := '' writeStream.
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   305
     s nextPutAll:'1234567890'.
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   306
     s position:5.
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   307
     s nextPutAll:'abcdefg'.
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   308
     s contents 
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   309
    "
6626
f7b08d6bee3f #positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents: 6538
diff changeset
   310
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   311
    "
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   312
     |s|
6626
f7b08d6bee3f #positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents: 6538
diff changeset
   313
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   314
     s := '' writeStream.
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   315
     s nextPutAll:'1234567890'.
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   316
     s position:0.
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   317
     s nextPutAll:'abcdefg'.
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   318
     s contents 
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   319
    "
6626
f7b08d6bee3f #positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents: 6538
diff changeset
   320
!
f7b08d6bee3f #positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents: 6538
diff changeset
   321
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   322
reset
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   323
    "set the read position to the beginning of the collection"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   324
5308
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   325
    self resetPosition
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   326
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   327
    "
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   328
     |s|
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   329
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   330
     s := 'hello world' readStream.
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   331
     Transcript showCR:(s next:5).
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   332
     s reset.
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   333
     Transcript showCR:(s next:10).
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   334
    "
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   335
!
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   336
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   337
resetPosition
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   338
    "set the read position to the beginning of the collection"
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   339
7114
acc13967229e position fixes
Claus Gittinger <cg@exept.de>
parents: 7092
diff changeset
   340
    position := ZeroPosition
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   341
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   342
    "
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   343
     |s|
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   344
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   345
     s := 'hello world' readStream.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   346
     Transcript showCR:(s next:5).
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   347
     s reset.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   348
     Transcript showCR:(s next:10).
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   349
    "
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   350
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   351
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   352
setToEnd
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   353
    "set the read position to the end of the collection"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   354
7114
acc13967229e position fixes
Claus Gittinger <cg@exept.de>
parents: 7092
diff changeset
   355
    position := readLimit - 1 + ZeroPosition
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   356
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   357
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   358
skip:numberToSkip
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   359
    "skip the next numberToSkip elements"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   360
5774
dafe65be735b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5748
diff changeset
   361
    numberToSkip ~~ 0 ifTrue:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   362
	self position:(self position + numberToSkip)
5774
dafe65be735b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5748
diff changeset
   363
    ]
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   364
!
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   365
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   366
skipThroughAll:aCollection
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   367
    "skip for and through the sequence given by the argument, aCollection;
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   368
     return nil if not found, self otherwise. 
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   369
     On a successful match, the next read will return elements after aCollection;
2153
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   370
     if no match was found, the receiver will be positioned at the end.
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   371
     This is redefined here, to make use of positioning."
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   372
7054
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   373
    |buffer len first idx|
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   374
7054
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   375
    len := aCollection size.
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   376
    first := aCollection at:1.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   377
    [self atEnd] whileFalse:[
7054
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   378
        buffer := self nextAvailable:len.
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   379
        buffer = aCollection ifTrue:[
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   380
            ^ self
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   381
        ].
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   382
        idx := buffer indexOf:first startingAt:2.
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   383
        idx == 0 ifFalse:[
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   384
            self position:(self position - len + idx - 1)
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   385
        ]
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   386
    ].
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   387
    ^ nil
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   388
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   389
    "
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   390
     |s|
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   391
     s := ReadStream on:'12345678901234567890'.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   392
     s skipThroughAll:'901'.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   393
     s upToEnd  
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   394
    "
2153
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   395
    "
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   396
     |s|
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   397
     s := ReadStream on:'12345678901234567890'.
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   398
     s skipThroughAll:'1234'.
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   399
     s upToEnd  
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   400
    "
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   401
    "
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   402
     |s|
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   403
     s := ReadStream on:'12345678901234567890'.
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   404
     s skipThroughAll:'999'.
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   405
     s atEnd  
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   406
    "
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   407
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   408
    "Created: 26.6.1996 / 09:35:35 / cg"
2154
89e96599e1e2 skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2153
diff changeset
   409
    "Modified: 11.1.1997 / 19:16:38 / cg"
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   410
!
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   411
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   412
skipToAll:aCollection
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   413
    "skip for the sequence given by the argument, aCollection;
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   414
     return nil if not found, self otherwise. 
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   415
     On a successful match, the next read will return elements of aCollection."
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   416
7054
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   417
    |oldPos buffer len first idx|
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   418
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   419
    oldPos := self position.
7054
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   420
    len := aCollection size.
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   421
    first := aCollection at:1.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   422
    [self atEnd] whileFalse:[
7054
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   423
        buffer := self next:len.
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   424
        buffer = aCollection ifTrue:[
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   425
            self position:(self position - len).
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   426
            ^ self
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   427
        ].
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   428
        idx := buffer indexOf:first startingAt:2.
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   429
        idx == 0 ifFalse:[
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   430
            self position:(self position - len + idx - 1)
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   431
        ]
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   432
    ].
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   433
    self position:oldPos.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   434
    ^ nil
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   435
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   436
    "
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   437
     |s|
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   438
     s := ReadStream on:'12345678901234567890'.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   439
     s skipToAll:'901'.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   440
     s upToEnd  
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   441
    "
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   442
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   443
    "Modified: 26.6.1996 / 09:28:27 / cg"
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   444
    "Created: 26.6.1996 / 09:35:06 / cg"
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   445
! !
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   446
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   447
!PositionableStream methodsFor:'private'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   448
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   449
contentsSpecies
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   450
    "return a class of which instances will be returned, when
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   451
     parts of the collection are asked for. 
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   452
     (see upTo-kind of methods in subclasses)"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   453
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   454
    ^ collection species
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   455
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   456
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   457
on:aCollection
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   458
    "setup for streaming on aCollection"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   459
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   460
    collection := aCollection.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   461
    readLimit := aCollection size.
7114
acc13967229e position fixes
Claus Gittinger <cg@exept.de>
parents: 7092
diff changeset
   462
    position := ZeroPosition
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   463
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   464
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   465
on:aCollection from:first to:last
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   466
    "setup for streaming on aCollection from first to last"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   467
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   468
    collection := aCollection.
7114
acc13967229e position fixes
Claus Gittinger <cg@exept.de>
parents: 7092
diff changeset
   469
    position := first - 1 + ZeroPosition.
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   470
    readLimit := last
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   471
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   472
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   473
positionError
1998
9749a5f87238 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   474
    "{ Pragma: +optSpace }"
9749a5f87238 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   475
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
   476
    "report an error when positioning past the end
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
   477
     or before the beginning."
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   478
8320
229adaeaf183 Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents: 8318
diff changeset
   479
    ^ PositionOutOfBoundsError raiseRequestWith:nil
4452
3d050f505a0a Raise proceedable signals proceedable.
Stefan Vogel <sv@exept.de>
parents: 4416
diff changeset
   480
3d050f505a0a Raise proceedable signals proceedable.
Stefan Vogel <sv@exept.de>
parents: 4416
diff changeset
   481
    "Modified: / 26.7.1999 / 10:59:13 / stefan"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   482
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   483
6314
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   484
positionError:badPostition
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   485
    "{ Pragma: +optSpace }"
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   486
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   487
    "report an error when positioning past the end
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   488
     or before the beginning."
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   489
8320
229adaeaf183 Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents: 8318
diff changeset
   490
    ^ PositionOutOfBoundsError raiseRequestWith:badPostition
6314
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   491
!
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   492
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   493
with:aCollection
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   494
    "setup for streaming to the end of aCollection"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   495
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   496
    collection := aCollection.
6230
877a8da90c7c fixed initial position in
Claus Gittinger <cg@exept.de>
parents: 6201
diff changeset
   497
    readLimit := aCollection size + 1.
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   498
    self setToEnd
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   499
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   500
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   501
!PositionableStream methodsFor:'queries'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   502
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   503
isPositionable
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   504
    "return true, if the stream supports positioning (this one is)"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   505
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   506
    ^ true
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   507
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   508
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   509
!PositionableStream methodsFor:'reading'!
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   510
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   511
upToAll:aCollection
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   512
    "read until a subcollection consisisting of the elements in aCollection
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   513
     is encountered.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   514
     Return everything read excluding the elements in aCollection.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   515
     The position is left before the collection; i.e. the next
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   516
     read operations will return those elements.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   517
     If no such subcollection is encountered, all elements up to the end 
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   518
     are read and returned.
6494
5b3d8667c22a comment
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   519
     See also #throughAll: which also reads up to some objects
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   520
     but positions behind it and DOES include it in the returned
3184
d99302322139 Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents: 3170
diff changeset
   521
     collection.
6494
5b3d8667c22a comment
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   522
     See also #upToAllExcluding:, which returns the same, but leaves the
5b3d8667c22a comment
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   523
     read pointer after the matched subcollection.
3184
d99302322139 Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents: 3170
diff changeset
   524
d99302322139 Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents: 3170
diff changeset
   525
     Note: this behavior is inconsistent with the other upTo.. methods,
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   526
	   which position after the found item. We implement the method
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   527
	   this way for the sake of ST80-compatibility."
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   528
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   529
    |answerStream element last rslt|
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   530
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   531
    last := aCollection last.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   532
    answerStream := WriteStream on:(self contentsSpecies new).
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   533
    [self atEnd] whileFalse:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   534
	element := self next.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   535
	answerStream nextPut:element.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   536
	element == last ifTrue:[
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   537
	    ((rslt := answerStream contents) endsWith:aCollection) ifTrue:[
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   538
		self position:(self position - aCollection size).
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   539
		^ rslt copyWithoutLast:aCollection size
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   540
	    ]
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   541
	].
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   542
    ].
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   543
    ^ answerStream contents
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   544
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   545
    "
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   546
     |s|
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   547
     s := ReadStream on:'hello world'.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   548
     Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. 
6494
5b3d8667c22a comment
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   549
     Transcript showCR:s atEnd.
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   550
     Transcript show:'<'; show:(s upToEnd); showCR:'>'. 
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   551
    "
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   552
    "
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   553
     |s|
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   554
     s := ReadStream on:'hello world'.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   555
     Transcript show:'<'; show:(s upToAll:'xx'); showCR:'>'. 
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   556
     Transcript showCR:s atEnd.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   557
     Transcript show:'<'; show:(s upToEnd); showCR:'>'. 
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   558
    "
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   559
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   560
    "Modified: / 12.1.1998 / 22:06:42 / cg"
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   561
    "Created: / 12.1.1998 / 22:07:01 / cg"
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   562
! !
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   563
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   564
!PositionableStream methodsFor:'testing'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   565
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   566
atEnd
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   567
    "return true, if the read-position is at the end"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   568
7114
acc13967229e position fixes
Claus Gittinger <cg@exept.de>
parents: 7092
diff changeset
   569
    ^ (position - ZeroPosition + 1) > readLimit
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   570
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   571
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   572
isEmpty
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   573
    "return true, if the contents of the stream is empty"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   574
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   575
    ^ readLimit == 0
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   576
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   577
1897
22d1ce9b62a4 fixes for packageQuery
Claus Gittinger <cg@exept.de>
parents: 1489
diff changeset
   578
!PositionableStream class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   579
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   580
version
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8363
diff changeset
   581
    ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.142 2004-07-13 08:39:04 cg Exp $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   582
! !
6777
5efddf5358b2 currentFileInDirectory query
Claus Gittinger <cg@exept.de>
parents: 6707
diff changeset
   583
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   584
PositionableStream initialize!