PositionableStream.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 18 Apr 2016 07:17:25 +0100
branchjv
changeset 19610 a9a6940944a9
parent 19412 1e842c25e51e
parent 19591 185835d2d0e5
child 19892 d1aecb538df5
permissions -rw-r--r--
Merge
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
"
5393
7e2230bd4bad moved some stuff to superclass
Claus Gittinger <cg@exept.de>
parents: 5308
diff changeset
    12
"{ Package: 'stx:libbasic' }"
7e2230bd4bad moved some stuff to superclass
Claus Gittinger <cg@exept.de>
parents: 5308
diff changeset
    13
17559
010577abda05 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16876
diff changeset
    14
"{ NameSpace: Smalltalk }"
010577abda05 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16876
diff changeset
    15
57
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    16
PeekableStream subclass:#PositionableStream
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
    17
	instanceVariableNames:'collection position readLimit writeLimit'
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8363
diff changeset
    18
	classVariableNames:'ZeroPosition InvalidPositionErrorSignal'
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
    19
	poolDictionaries:''
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
    20
	category:'Streams'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    22
1897
22d1ce9b62a4 fixes for packageQuery
Claus Gittinger <cg@exept.de>
parents: 1489
diff changeset
    23
!PositionableStream class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    25
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    26
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    27
 COPYRIGHT (c) 1989 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
    28
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    29
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    37
!
10
claus
parents: 5
diff changeset
    38
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    39
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    41
    Instances of PositionableStream allow positioning the read pointer.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    42
    The PositionableStream class also adds methods for source-chunk reading
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    43
    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
    44
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    45
    This is an abstract class.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
    46
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
    47
    Compatibility Notice:
9434
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
    48
        In previous versions of ST/X, streams started with a 1-position (i.e. as in collections),
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
    49
        while ST-80 has always been using 0-based postions for streams and 1-based positions for collections.
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
    50
17559
010577abda05 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16876
diff changeset
    51
        THIS CERTAINLY IS BAD.
010577abda05 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16876
diff changeset
    52
010577abda05 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16876
diff changeset
    53
        Although this is confusing ST/X has been changed to now also uses 0-based stream positioning.
9434
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
    54
17559
010577abda05 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16876
diff changeset
    55
    [caveat:]
010577abda05 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16876
diff changeset
    56
        Basing capabilities like readability/writability/positionability/peekability on inheritance makes
010577abda05 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16876
diff changeset
    57
        the class hierarchy ugly and leads to strange and hard to teach redefinitions (aka. NonPositionableStream
010577abda05 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16876
diff changeset
    58
        below PositionableStream or ExternalReadStream under WriteStream)
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
    59
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
    60
    [author:]
9434
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
    61
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    62
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    63
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    64
1897
22d1ce9b62a4 fixes for packageQuery
Claus Gittinger <cg@exept.de>
parents: 1489
diff changeset
    65
!PositionableStream class methodsFor:'initialization'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    66
10
claus
parents: 5
diff changeset
    67
initialize
15353
0a60d904c4c0 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15348
diff changeset
    68
    ZeroPosition := 0.        "/ changed with stx rel5.1; 
0a60d904c4c0 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15348
diff changeset
    69
                              "/ rel6.2: no longer used (i.e. 0 has now ben hardcoded)
0a60d904c4c0 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15348
diff changeset
    70
                              "/ class variable to be eliminated.
7363
721c2a72449a stream position now 0-based
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
    71
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8363
diff changeset
    72
    InvalidPositionErrorSignal isNil ifTrue:[
7092
630807cd320f Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents: 7054
diff changeset
    73
        InvalidPositionErrorSignal := PositionOutOfBoundsError.
630807cd320f Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents: 7054
diff changeset
    74
        InvalidPositionErrorSignal notifierString:'position out of bounds: '.
10
claus
parents: 5
diff changeset
    75
    ]
claus
parents: 5
diff changeset
    76
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    77
1897
22d1ce9b62a4 fixes for packageQuery
Claus Gittinger <cg@exept.de>
parents: 1489
diff changeset
    78
!PositionableStream class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    79
a27a279701f8 Initial revision
claus
parents:
diff changeset
    80
on:aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
    81
    "return a new PositionableStream streaming on aCollection"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    82
a27a279701f8 Initial revision
claus
parents:
diff changeset
    83
    ^ (self basicNew) on:aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
    84
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    85
a27a279701f8 Initial revision
claus
parents:
diff changeset
    86
on:aCollection from:first to:last
a27a279701f8 Initial revision
claus
parents:
diff changeset
    87
    "return a new PositionableStream streaming on aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
    88
     from first to last"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    89
369
claus
parents: 362
diff changeset
    90
    ^ (self basicNew) on:aCollection from:first to:last
57
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    91
!
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    92
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    93
with:aCollection
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    94
    "return a new PositionableStream streaming on aCollection,
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    95
     the stream is positioned to the end of the collection."
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    96
362
claus
parents: 360
diff changeset
    97
    ^ (self basicNew) with:aCollection
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    98
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
    99
3032
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   100
!PositionableStream class methodsFor:'Signal constants'!
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   101
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   102
invalidPositionErrorSignal
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   103
    "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
   104
     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
   105
     the end)"
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   106
8320
229adaeaf183 Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents: 8318
diff changeset
   107
    ^ PositionOutOfBoundsError
3032
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   108
! !
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   109
1897
22d1ce9b62a4 fixes for packageQuery
Claus Gittinger <cg@exept.de>
parents: 1489
diff changeset
   110
!PositionableStream class methodsFor:'constants'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   111
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   112
zeroPosition
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   113
    "return the number, which marks the initial position.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   114
     Compatibility Notice:
9434
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
   115
        In previous versions of ST/X, streams started with a 1-position (i.e. as in collections),
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
   116
        while ST-80 has always been using 0-based postions for streams and 1-based positions for collections.
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   117
9434
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
   118
     Although this is confusing ST/X has been changed to now also use 0-based stream positioning.
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
   119
    "
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   120
15353
0a60d904c4c0 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15348
diff changeset
   121
    ^ 0
9434
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
   122
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
   123
    "Modified: / 13-07-2006 / 20:36:54 / cg"
360
claus
parents: 329
diff changeset
   124
! !
claus
parents: 329
diff changeset
   125
17606
b30bac248329 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17559
diff changeset
   126
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7226
diff changeset
   127
!PositionableStream methodsFor:'Compatibility-Dolphin'!
6413
dc8d492a39ff dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6361
diff changeset
   128
dc8d492a39ff dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6361
diff changeset
   129
endChunk
dc8d492a39ff dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6361
diff changeset
   130
    self nextPutChunkSeparator
dc8d492a39ff dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6361
diff changeset
   131
! !
dc8d492a39ff dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6361
diff changeset
   132
9284
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   133
!PositionableStream methodsFor:'Compatibility-ST/V'!
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   134
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   135
skipTo:anElement
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   136
    "ST/V compatibility:
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   137
     skip for the element given by the argument, anElement;
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   138
     return nil if not found, self otherwise. 
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   139
     On a successful match, the next read will return the element after anElement."
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   140
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   141
    ^ self skipThrough:anElement
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   142
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   143
    "
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   144
     |s|
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   145
     s := ReadStream on:'12345678901234567890'.
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   146
     s skipTo:$5.
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   147
     s copyFrom:1 to:(s position).    
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   148
     s upToEnd      
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   149
    "
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   150
! !
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   151
16876
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   152
!PositionableStream methodsFor:'Compatibility-Squeak'!
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   153
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   154
back
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   155
        "Go back one element and return it."
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   156
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   157
        self position = 0 ifTrue: [self positionError].
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   158
        self skip: -1.
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   159
        ^ self peek
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   160
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   161
    "Created: / 03-10-2014 / 03:06:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   162
!
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   163
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   164
peekBack
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   165
        "Return the element at the previous position, without changing position.  Use indirect messages in case self is a StandardFileStream."
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   166
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   167
        | element |
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   168
        element := self back.
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   169
        self skip: 1.
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   170
        ^ element
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   171
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   172
    "Created: / 03-10-2014 / 03:06:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
18260
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   173
!
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   174
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   175
upToAnyOf: aCollection 
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   176
        "Answer a subcollection from the current access position to the 
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   177
        occurrence (if any, but not inclusive) of any object in the collection. If 
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   178
        no matching object is found, answer the entire rest of the receiver."
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   179
        ^self upToAnyOf: aCollection do: [:matchingObject | ]
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   180
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   181
    "Created: / 21-04-2015 / 17:25:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   182
!
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   183
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   184
upToAnyOf: subcollection do: aBlock
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   185
        "Answer a subcollection from the current access position to the occurrence (if any, but not inclusive) of any object in the collection.
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   186
        Evaluate aBlock with this occurence as argument.
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   187
        If no matching object is found, don't evaluate aBlock and answer the entire rest of the receiver."
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   188
        
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   189
        ^self collection species new: 1000 streamContents: [ :stream |
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   190
                | ch |
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   191
                [ self atEnd or: [ (subcollection includes: (ch := self next)) and: [aBlock value: ch. true] ] ] 
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   192
                        whileFalse: [ stream nextPut: ch ] ]
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   193
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   194
    "Created: / 21-04-2015 / 17:26:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
16876
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   195
! !
7e3ad01ca413 Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16840
diff changeset
   196
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   197
!PositionableStream methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   198
7686
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7619
diff changeset
   199
collection
19591
185835d2d0e5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19403
diff changeset
   200
    "return the underlying collection buffer.
185835d2d0e5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19403
diff changeset
   201
     Notice, that this buffer may become invalid after being retrieved,
185835d2d0e5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19403
diff changeset
   202
     if more data is written to the stream (because a bigger buffer might be
185835d2d0e5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19403
diff changeset
   203
     allocated). Therefore, it should be only used in special situations,
185835d2d0e5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19403
diff changeset
   204
     where an already filed buffer needs to be backpatched later
185835d2d0e5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19403
diff changeset
   205
     (eg. before being sent out to some external stream or socket)"
185835d2d0e5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19403
diff changeset
   206
    
7686
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7619
diff changeset
   207
    ^ collection
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7619
diff changeset
   208
!
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7619
diff changeset
   209
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   210
contents
a27a279701f8 Initial revision
claus
parents:
diff changeset
   211
    "return the entire contents of the stream"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   212
a27a279701f8 Initial revision
claus
parents:
diff changeset
   213
    ^ collection
a27a279701f8 Initial revision
claus
parents:
diff changeset
   214
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   215
a27a279701f8 Initial revision
claus
parents:
diff changeset
   216
peek
a27a279701f8 Initial revision
claus
parents:
diff changeset
   217
    "look ahead for and return the next element"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   218
a27a279701f8 Initial revision
claus
parents:
diff changeset
   219
    |peekObject|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   220
a27a279701f8 Initial revision
claus
parents:
diff changeset
   221
    peekObject := self next.
10
claus
parents: 5
diff changeset
   222
    self backStep.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   223
    ^ peekObject
a27a279701f8 Initial revision
claus
parents:
diff changeset
   224
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   225
2432
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   226
peekForAll:aCollection
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   227
    "return true and advance if the next elements are the same
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   228
     as aCollection. 
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   229
     otherwise stay and let the position unchanged"
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   230
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   231
    |oldPos|
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   232
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   233
    oldPos := self position.
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   234
    (self next:(aCollection size)) = aCollection ifTrue:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   235
	^ true
2432
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   236
    ].
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   237
    self position:oldPos.
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   238
    ^ false
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   239
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   240
    "Created: 1.3.1997 / 15:11:25 / cg"
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   241
!
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   242
3905
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   243
readLimit
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   244
    "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
   245
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   246
    ^ readLimit
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   247
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   248
    "Created: / 30.10.1998 / 16:47:04 / cg"
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   249
!
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   250
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   251
readLimit:aNumber
369
claus
parents: 362
diff changeset
   252
    "set the read-limit; thats the position at which EOF is returned"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   253
a27a279701f8 Initial revision
claus
parents:
diff changeset
   254
    readLimit := aNumber
369
claus
parents: 362
diff changeset
   255
!
claus
parents: 362
diff changeset
   256
14934
5e273cddded7 setCollection: moved
Claus Gittinger <cg@exept.de>
parents: 13379
diff changeset
   257
setCollection:newCollection
5e273cddded7 setCollection: moved
Claus Gittinger <cg@exept.de>
parents: 13379
diff changeset
   258
    collection := newCollection
5e273cddded7 setCollection: moved
Claus Gittinger <cg@exept.de>
parents: 13379
diff changeset
   259
!
5e273cddded7 setCollection: moved
Claus Gittinger <cg@exept.de>
parents: 13379
diff changeset
   260
369
claus
parents: 362
diff changeset
   261
writeLimit:aNumber
claus
parents: 362
diff changeset
   262
    "set the writeLimit; thats the position after which writing is prohibited"
claus
parents: 362
diff changeset
   263
claus
parents: 362
diff changeset
   264
    writeLimit := aNumber
10592
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   265
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   266
    "
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   267
     |s|
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   268
     s := WriteStream on:String new.
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   269
     s nextPutAll:'hello world'.
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   270
     s contents.
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   271
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   272
     |s|
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   273
     s := WriteStream on:String new.
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   274
     s writeLimit:5.
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   275
     s nextPutAll:'hello world'.
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   276
     s contents.
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   277
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   278
    "
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   279
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   280
    "Modified: / 04-06-2007 / 17:21:55 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   281
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   282
17611
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   283
!PositionableStream methodsFor:'misc functions'!
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   284
19403
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   285
copyToEndInto:aWriteStream
17611
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   286
    "read from the receiver, and write all data up to the end to another stream.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   287
     Return the number of bytes which have been transferred.
19403
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   288
     Redefined here to avoid intermediate buffers/garbage."
17611
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   289
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   290
    |cnt|
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   291
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   292
    collection notNil ifTrue:[
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   293
        aWriteStream nextPutAll:collection startingAt:position+1 to:readLimit.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   294
        cnt := readLimit - position.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   295
        position := readLimit.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   296
        ^ cnt.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   297
    ].
19403
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   298
    ^ super copyToEndInto:aWriteStream.
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   299
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   300
    "
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   301
     |rs ws cnt|
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   302
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   303
     ws := #() writeStream.
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   304
     rs := #( 1 2 3 4 a nil true) readWriteStream.
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   305
     rs next.
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   306
     cnt := rs copyToEndInto:ws bufferSize:0.
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   307
     Transcript show:cnt; show:' '; showCR:ws contents.
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   308
    "
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   309
!
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   310
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   311
copyToEndInto:aWriteStream bufferSize:bufferSize
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   312
    "read from the receiver, and write all data up to the end to another stream.
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   313
     Return the number of bytes which have been transferred.
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   314
     Redefined here to avoid intermediate buffers/garbage.
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   315
     bufferSize does not matter here."
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   316
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   317
    collection notNil ifTrue:[
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   318
        ^ self copyToEndInto:aWriteStream.
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   319
    ].
17611
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   320
    ^ super copyToEndInto:aWriteStream bufferSize:bufferSize.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   321
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   322
    "
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   323
     |rs ws cnt|
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   324
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   325
     ws := #() writeStream.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   326
     rs := #( 1 2 3 4 a nil true) readWriteStream.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   327
     rs next.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   328
     cnt := rs copyToEndInto:ws bufferSize:0.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   329
     Transcript show:cnt; show:' '; showCR:ws contents.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   330
    "
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   331
! !
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   332
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   333
!PositionableStream methodsFor:'positioning'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   334
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   335
backStep
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   336
    "move backward read position by one"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   337
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   338
    self position:(self position - 1)
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   339
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   340
16188
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   341
match: subCollection
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   342
    "Set the access position of the receiver to be past the next occurrence of the subCollection. 
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   343
     Answer whether subCollection is found.  
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   344
     No wildcards, and case does matter."
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   345
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   346
    | pattern startMatch |
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   347
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   348
    pattern := ReadStream on: subCollection.
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   349
    startMatch := nil.
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   350
    [pattern atEnd] whileFalse: [
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   351
        self atEnd ifTrue: [^ false].
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   352
        (self next) = (pattern next) 
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   353
            ifTrue: [pattern position = 1 ifTrue: [startMatch := self position]]
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   354
            ifFalse: [
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   355
                pattern position: 0.
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   356
                startMatch ifNotNil: [
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   357
                    self position: startMatch.
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   358
                    startMatch := nil
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   359
                ]
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   360
            ]
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   361
    ].
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   362
    ^ true
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   363
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   364
    "
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   365
     'abc def ghi' readStream match:'def'; upToEnd
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   366
    "
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   367
!
4df8b9b15db4 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16186
diff changeset
   368
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   369
position
15615
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   370
    "return the read position (0-based)"
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   371
15348
f5677dc62dc0 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15159
diff changeset
   372
    ^ position
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   373
!
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   374
15615
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   375
position0Based
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   376
    <resource: #obsolete>
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   377
    "return the read position 0-based"
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   378
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   379
    ^ self position
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   380
!
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   381
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   382
position0Based:index0Based
15615
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   383
    <resource: #obsolete>
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   384
    "set the read (or write) position"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   385
15615
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   386
    self position:index0Based
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   387
!
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   388
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   389
position1Based
15615
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   390
    <resource: #obsolete>
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   391
    "return the read position 1-based"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   392
15615
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   393
    ^ self position + 1
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   394
!
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   395
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   396
position1Based:index1Based
15615
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   397
    <resource: #obsolete>
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   398
    "set the read (or write) position"
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   399
15615
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   400
    self position:(index1Based - 1)
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   401
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   402
    "
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   403
     |s|
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   404
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   405
     s := '1234567890' readStream.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   406
     s next:5.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   407
     s position:1.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   408
     s next:7.       
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   409
    "
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   410
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   411
    "
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   412
     |s|
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   413
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   414
     s := '' writeStream.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   415
     s nextPutAll:'1234567890'.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   416
     s position:5.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   417
     s nextPutAll:'abcdefg'.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   418
     s contents 
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   419
    "
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   420
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   421
    "
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   422
     |s|
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   423
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   424
     s := '' writeStream.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   425
     s nextPutAll:'1234567890'.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   426
     s position:0.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   427
     s nextPutAll:'abcdefg'.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   428
     s contents 
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   429
    "
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   430
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   431
15615
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   432
position:index0Based
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   433
    "set the read (or write) position"
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   434
15615
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   435
    ((index0Based > readLimit) or:[index0Based < 0]) ifTrue: [^ self positionError:index0Based].
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   436
    position := index0Based
6626
f7b08d6bee3f #positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents: 6538
diff changeset
   437
!
f7b08d6bee3f #positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents: 6538
diff changeset
   438
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   439
reset
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   440
    "set the read position to the beginning of the collection"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   441
5308
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   442
    self resetPosition
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   443
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   444
    "
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   445
     |s|
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   446
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   447
     s := 'hello world' readStream.
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   448
     Transcript showCR:(s next:5).
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   449
     s reset.
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   450
     Transcript showCR:(s next:10).
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   451
    "
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   452
!
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   453
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   454
resetPosition
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   455
    "set the read position to the beginning of the collection"
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   456
15348
f5677dc62dc0 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15159
diff changeset
   457
    position := 0
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   458
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   459
    "
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   460
     |s|
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   461
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   462
     s := 'hello world' readStream.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   463
     Transcript showCR:(s next:5).
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   464
     s reset.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   465
     Transcript showCR:(s next:10).
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   466
    "
611
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
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   469
setToEnd
11433
bf4acfe61ece changed #setToEnd
Stefan Vogel <sv@exept.de>
parents: 10592
diff changeset
   470
    "set the read position to the end of the collection.
bf4acfe61ece changed #setToEnd
Stefan Vogel <sv@exept.de>
parents: 10592
diff changeset
   471
     #next will return EOF, #nextPut: will append to the stream.
bf4acfe61ece changed #setToEnd
Stefan Vogel <sv@exept.de>
parents: 10592
diff changeset
   472
     (same Behavior as FileStream."
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   473
15348
f5677dc62dc0 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15159
diff changeset
   474
    position := readLimit
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   475
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   476
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   477
skip:numberToSkip
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   478
    "skip the next numberToSkip elements"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   479
5774
dafe65be735b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5748
diff changeset
   480
    numberToSkip ~~ 0 ifTrue:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   481
	self position:(self position + numberToSkip)
5774
dafe65be735b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5748
diff changeset
   482
    ]
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   483
!
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   484
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   485
skipThroughAll:aCollection
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   486
    "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
   487
     return nil if not found, self otherwise. 
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   488
     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
   489
     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
   490
     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
   491
7054
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   492
    |buffer len first idx|
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   493
16186
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   494
    self isPositionable ifFalse:[
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   495
        "/ for non-positionable subclasses
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   496
        ^ super skipThroughAll:aCollection
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   497
    ].
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   498
7054
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   499
    len := aCollection size.
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   500
    first := aCollection at:1.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   501
    [self atEnd] whileFalse:[
7054
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   502
        buffer := self nextAvailable:len.
10357
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   503
        buffer size == len ifTrue:[
16209
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   504
            buffer = aCollection ifTrue:[
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   505
                ^ self
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   506
            ].
10357
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   507
            "expect more input"
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   508
            idx := buffer indexOf:first startingAt:2.
16209
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   509
            idx ~~ 0 ifTrue:[
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   510
                self skip:(idx - len - 1)
10357
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   511
            ].
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   512
        ].
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   513
    ].
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   514
    ^ nil
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   515
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   516
    "
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   517
     |s|
10357
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   518
     s := ReadStream on:'12345678901234567890a'.
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   519
     s skipThroughAll:'90ab'.
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   520
     s upToEnd  
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   521
    "
2153
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   522
    "
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   523
     |s|
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   524
     s := ReadStream on:'12345678901234567890'.
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   525
     s skipThroughAll:'1234'.
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   526
     s upToEnd  
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   527
    "
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   528
    "
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   529
     |s|
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   530
     s := ReadStream on:'12345678901234567890'.
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   531
     s skipThroughAll:'999'.
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   532
     s atEnd  
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   533
    "
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   534
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   535
    "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
   536
    "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
   537
!
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   538
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   539
skipToAll:aCollection
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   540
    "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
   541
     return nil if not found, self otherwise. 
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   542
     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
   543
7054
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   544
    |oldPos buffer len first idx|
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   545
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   546
    oldPos := self position.
7054
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   547
    len := aCollection size.
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   548
    first := aCollection at:1.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   549
    [self atEnd] whileFalse:[
10357
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   550
        buffer := self nextAvailable:len.
7054
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   551
        buffer = aCollection ifTrue:[
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   552
            self position:(self position - len).
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   553
            ^ self
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   554
        ].
10357
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   555
        buffer size == len ifTrue:[
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   556
            "more input can be expected"
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   557
            idx := buffer indexOf:first startingAt:2.
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   558
            idx == 0 ifFalse:[
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   559
                self position:(self position - len + idx - 1)
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   560
            ].
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   561
        ].
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   562
    ].
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   563
    self position:oldPos.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   564
    ^ nil
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   565
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   566
    "
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   567
     |s|
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   568
     s := ReadStream on:'12345678901234567890'.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   569
     s skipToAll:'901'.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   570
     s upToEnd  
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   571
    "
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   572
10357
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   573
    "
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   574
     |s|
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   575
     s := ReadStream on:'1234567890'.
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   576
     s skipToAll:'901'.
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   577
     s upToEnd  
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   578
    "
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   579
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   580
    "
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   581
     |s|
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   582
     s := 'Makefile' asFilename readStream.
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   583
     [
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   584
         (s skipToAll:'EDIT') notNil ifTrue:[
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   585
            s next:100.
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   586
         ].
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   587
     ] ensure:[
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   588
        s close.
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   589
     ]
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   590
    "
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   591
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   592
    "Modified: 26.6.1996 / 09:28:27 / cg"
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   593
    "Created: 26.6.1996 / 09:35:06 / cg"
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   594
! !
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   595
10357
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   596
!PositionableStream methodsFor:'printing & storing'!
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   597
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   598
printOn:aStream
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   599
    aStream nextPutAll:self className; nextPutAll:'(on:'; nextPutAll:collection classNameWithArticle; nextPut:$)
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   600
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   601
    "
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   602
      '' readStream printString
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   603
      '' writeStream printString
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   604
    "
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   605
! !
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   606
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   607
!PositionableStream methodsFor:'private'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   608
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   609
contentsSpecies
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   610
    "return a class of which instances will be returned, when
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   611
     parts of the collection are asked for. 
15640
d5a8c24894e2 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15615
diff changeset
   612
     (see upTo-kind of methods in Stream)"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   613
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   614
    ^ collection species
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   615
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   616
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   617
on:aCollection
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   618
    "setup for streaming on aCollection"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   619
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   620
    collection := aCollection.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   621
    readLimit := aCollection size.
13379
a4644dee3177 changed: #on:
sr
parents: 11434
diff changeset
   622
    readLimit == 0 ifTrue:[
a4644dee3177 changed: #on:
sr
parents: 11434
diff changeset
   623
        self assert:(aCollection isCollection)
a4644dee3177 changed: #on:
sr
parents: 11434
diff changeset
   624
    ].
15348
f5677dc62dc0 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15159
diff changeset
   625
    position := 0
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   626
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   627
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   628
on:aCollection from:first to:last
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   629
    "setup for streaming on aCollection from first to last"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   630
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   631
    collection := aCollection.
15348
f5677dc62dc0 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15159
diff changeset
   632
    position := first - 1.
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   633
    readLimit := last
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   634
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   635
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   636
positionError
1998
9749a5f87238 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   637
    "{ Pragma: +optSpace }"
9749a5f87238 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   638
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
   639
    "report an error when positioning past the end
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
   640
     or before the beginning."
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   641
8320
229adaeaf183 Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents: 8318
diff changeset
   642
    ^ PositionOutOfBoundsError raiseRequestWith:nil
4452
3d050f505a0a Raise proceedable signals proceedable.
Stefan Vogel <sv@exept.de>
parents: 4416
diff changeset
   643
3d050f505a0a Raise proceedable signals proceedable.
Stefan Vogel <sv@exept.de>
parents: 4416
diff changeset
   644
    "Modified: / 26.7.1999 / 10:59:13 / stefan"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   645
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   646
6314
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   647
positionError:badPostition
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   648
    "{ Pragma: +optSpace }"
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   649
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   650
    "report an error when positioning past the end
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   651
     or before the beginning."
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   652
8320
229adaeaf183 Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents: 8318
diff changeset
   653
    ^ PositionOutOfBoundsError raiseRequestWith:badPostition
6314
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   654
!
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   655
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   656
with:aCollection
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   657
    "setup for streaming to the end of aCollection"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   658
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   659
    collection := aCollection.
11434
525e70af011a changed #with:
Stefan Vogel <sv@exept.de>
parents: 11433
diff changeset
   660
    readLimit := aCollection size.
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   661
    self setToEnd
11434
525e70af011a changed #with:
Stefan Vogel <sv@exept.de>
parents: 11433
diff changeset
   662
525e70af011a changed #with:
Stefan Vogel <sv@exept.de>
parents: 11433
diff changeset
   663
    "
525e70af011a changed #with:
Stefan Vogel <sv@exept.de>
parents: 11433
diff changeset
   664
      (WriteStream with:#(1 2 3 4 5)) 
525e70af011a changed #with:
Stefan Vogel <sv@exept.de>
parents: 11433
diff changeset
   665
            nextPut:6;
525e70af011a changed #with:
Stefan Vogel <sv@exept.de>
parents: 11433
diff changeset
   666
            contents
525e70af011a changed #with:
Stefan Vogel <sv@exept.de>
parents: 11433
diff changeset
   667
    "
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   668
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   669
16195
2bed37c6f731 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16189
diff changeset
   670
!PositionableStream methodsFor:'queries'!
2bed37c6f731 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16189
diff changeset
   671
16209
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   672
endsBeforePositionWith:aSequenceableCollection
16195
2bed37c6f731 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16189
diff changeset
   673
    "answer true, if the elements in aSequenceableCollection
16209
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   674
     are at the current end of the stream up to position."
16195
2bed37c6f731 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16189
diff changeset
   675
16209
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   676
    |sz pos|
16195
2bed37c6f731 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16189
diff changeset
   677
16209
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   678
    sz := aSequenceableCollection size.
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   679
    pos := self position.
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   680
    pos < sz ifTrue:[
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   681
        ^ false.
16195
2bed37c6f731 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16189
diff changeset
   682
    ].
16209
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   683
    self contentsSpecies == collection class ifTrue:[
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   684
        ^ collection sameContentsFrom:pos+1-sz to:pos as:aSequenceableCollection startingAt:1.
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   685
    ].
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   686
    self position:pos-sz.
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   687
    ^ (self next:sz) = aSequenceableCollection.
16195
2bed37c6f731 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16189
diff changeset
   688
2bed37c6f731 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16189
diff changeset
   689
    "
16209
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   690
        ('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'World'
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   691
        ('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'Hello World'
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   692
        ('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'Hello Worldx'
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   693
        ('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'Bla'
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   694
        ('' writeStream) endsBeforePositionWith:'Bla'
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   695
        ('' writeStream) endsBeforePositionWith:''
16195
2bed37c6f731 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16189
diff changeset
   696
        ''  endsWith:''
2bed37c6f731 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16189
diff changeset
   697
    "
2bed37c6f731 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16189
diff changeset
   698
! !
2bed37c6f731 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16189
diff changeset
   699
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   700
!PositionableStream methodsFor:'reading'!
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   701
9003
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   702
nextAvailable:count
17606
b30bac248329 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17559
diff changeset
   703
    collection notNil ifTrue:[
b30bac248329 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17559
diff changeset
   704
        |end result|
9003
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   705
17606
b30bac248329 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17559
diff changeset
   706
        end := position + count.
b30bac248329 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17559
diff changeset
   707
        end >= readLimit ifTrue:[
b30bac248329 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17559
diff changeset
   708
            end := readLimit.
b30bac248329 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17559
diff changeset
   709
        ].
b30bac248329 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17559
diff changeset
   710
b30bac248329 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17559
diff changeset
   711
        result := collection copyFrom:position+1 to:end.
b30bac248329 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17559
diff changeset
   712
        position := end.
b30bac248329 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17559
diff changeset
   713
        ^ result.
9003
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   714
    ].
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   715
17606
b30bac248329 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17559
diff changeset
   716
    ^ super nextAvailable:count.
9003
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   717
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   718
    "
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   719
        'abc' readStream nextAvailable:1.
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   720
        'abc' readStream nextAvailable:2.
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   721
        'abc' readStream nextAvailable:3.
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   722
        'abc' readStream nextAvailable:4.
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   723
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   724
        'abc' readStream nextAvailable:2; nextAvailable:2.
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   725
        'abc' readStream nextAvailable:3; nextAvailable:3.
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   726
    "
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   727
!
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   728
17611
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   729
nextAvailable:count into:aCollection startingAt:initialIndex
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   730
    "return the next count objects from the stream. If the end is
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   731
     reached before, only that many objects are copyied into the
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   732
     collection.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   733
     Returns the number of objects that have been actually read."
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   734
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   735
    | max |
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   736
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   737
    collection notNil ifTrue:[
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   738
        max := (readLimit - position) min: count.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   739
        aCollection
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   740
            replaceFrom: initialIndex
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   741
            to: initialIndex+max-1
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   742
            with: collection
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   743
            startingAt: position+1.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   744
        position := position + max.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   745
        ^ max.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   746
    ].
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   747
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   748
    ^ super nextAvailable:count into:aCollection startingAt:initialIndex.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   749
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   750
    "
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   751
     |s n buffer|
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   752
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   753
     buffer := ByteArray new:10.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   754
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   755
     s := ReadStream on:#[1 2 3 4 5 6 7 8 9].
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   756
     s next:3.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   757
     n := s nextBytes:9 into:buffer startingAt:1.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   758
     Transcript showCR:('n = %1; buffer = <%2>' bindWith:n with:buffer)
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   759
    "
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   760
!
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   761
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   762
nextBytes:numBytes into:aCollection startingAt:initialIndex
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   763
    "return the next numBytes from the stream. If the end is
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   764
     reached before, only that many bytes are copyied into the
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   765
     collection.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   766
     Returns the number of bytes that have been actually read.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   767
     The receiver must support reading of binary bytes.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   768
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   769
     Notice: this method is provided here for protocol completeness
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   770
             with externalStreams - it is normally not used with other
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   771
             streams."
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   772
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   773
    |max|
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   774
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   775
    (collection isByteCollection
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   776
     and:[aCollection isByteCollection]) ifTrue:[
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   777
        "do it the fast way"
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   778
        max := (readLimit - position) min: numBytes.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   779
        aCollection
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   780
            replaceBytesFrom:initialIndex 
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   781
            to:(initialIndex + max - 1)
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   782
            with:collection 
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   783
            startingAt:position+1.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   784
        position := position + max.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   785
        ^ max
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   786
    ].
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   787
    "do it the hard way"
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   788
    ^ super nextBytes:numBytes into:aCollection startingAt:initialIndex
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   789
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   790
    "
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   791
     |s n buffer|
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   792
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   793
     buffer := ByteArray new:10.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   794
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   795
     s := ReadStream on:#[1 2 3 4 5 6 7 8 9].
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   796
     s next:3.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   797
     n := s nextBytes:9 into:buffer startingAt:1.
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   798
     Transcript showCR:('n = %1; buffer = <%2>' bindWith:n with:buffer)
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   799
    "
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   800
!
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   801
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   802
upToAll:aCollection
16186
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   803
    "read until a subcollection consisisting of the elements in aCollection is encountered.
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   804
     Return everything read excluding the elements in aCollection.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   805
     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
   806
     read operations will return those elements.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   807
     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
   808
     are read and returned.
6494
5b3d8667c22a comment
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   809
     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
   810
     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
   811
     collection.
6494
5b3d8667c22a comment
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   812
     See also #upToAllExcluding:, which returns the same, but leaves the
5b3d8667c22a comment
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   813
     read pointer after the matched subcollection.
3184
d99302322139 Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents: 3170
diff changeset
   814
d99302322139 Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents: 3170
diff changeset
   815
     Note: this behavior is inconsistent with the other upTo.. methods,
15159
b94bdee97afa Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 14934
diff changeset
   816
           which position after the found item. We implement the method
b94bdee97afa Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 14934
diff changeset
   817
           this way for the sake of ST80-compatibility."
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   818
17611
a3d9a43a6197 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 17606
diff changeset
   819
    "/ in the future, this will have the Squeak semantics, which is upToAllExcluding:
16189
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   820
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   821
    ^ self upToAll_positionBefore:aCollection
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   822
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   823
    "
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   824
     |s|
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   825
     s := ReadStream on:'hello world'.
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   826
     Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. 
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   827
     Transcript showCR:s atEnd.
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   828
     Transcript show:'<'; show:(s upToEnd); showCR:'>'. 
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   829
    "
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   830
    "
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   831
     |s|
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   832
     s := ReadStream on:'hello world'.
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   833
     Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. 
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   834
     Transcript showCR:s atEnd.
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   835
     Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. 
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   836
    "
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   837
    "
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   838
     |s|
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   839
     s := ReadStream on:'hello world'.
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   840
     Transcript show:'<'; show:(s upToAll:'xx'); showCR:'>'. 
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   841
     Transcript showCR:s atEnd.
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   842
     Transcript show:'<'; show:(s upToEnd); showCR:'>'. 
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   843
    "
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   844
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   845
    "Modified: / 12.1.1998 / 22:06:42 / cg"
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   846
    "Created: / 12.1.1998 / 22:07:01 / cg"
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   847
!
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   848
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   849
upToAll_positionBefore:aCollection
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   850
    "read until a subcollection consisisting of the elements in aCollection is encountered.
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   851
     Return everything read excluding the elements in aCollection.
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   852
     The position is left before the collection; i.e. the next
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   853
     read operations will return those elements.
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   854
     If no such subcollection is encountered, all elements up to the end 
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   855
     are read and returned.
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   856
     See also #throughAll: which also reads up to some objects
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   857
     but positions behind it and DOES include it in the returned
16840
48075991f9d9 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16209
diff changeset
   858
     collection."
16189
d7b9978c07bb class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 16188
diff changeset
   859
16209
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   860
    |answerStream element last|
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   861
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   862
    last := aCollection last.
16209
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   863
    answerStream := WriteStream on:(self contentsSpecies new:100).
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   864
    [(element := self nextOrNil) notNil] whileTrue:[
15159
b94bdee97afa Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 14934
diff changeset
   865
        answerStream nextPut:element.
16209
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   866
        (element = last and:[answerStream endsBeforePositionWith:aCollection]) ifTrue:[
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   867
            |backStep|
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   868
            backStep := aCollection size negated.
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   869
            self skip:backStep.
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   870
            answerStream skip:backStep.
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   871
            ^ answerStream contents
15159
b94bdee97afa Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 14934
diff changeset
   872
        ].
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   873
    ].
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   874
    ^ answerStream contents
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   875
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   876
    "
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   877
     |s|
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   878
     s := ReadStream on:'hello world'.
16209
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   879
     Transcript show:'<'; show:(s upToAll_positionBefore:'wo'); showCR:'>'. 
6494
5b3d8667c22a comment
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   880
     Transcript showCR:s atEnd.
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   881
     Transcript show:'<'; show:(s upToEnd); showCR:'>'. 
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   882
    "
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   883
    "
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   884
     |s|
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   885
     s := ReadStream on:'hello world'.
16209
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   886
     Transcript show:'<'; show:(s upToAll_positionBefore:'wo'); showCR:'>'. 
16186
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   887
     Transcript showCR:s atEnd.
16209
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   888
     Transcript show:'<'; show:(s upToAll_positionBefore:'wo'); showCR:'>'. 
16186
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   889
    "
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   890
    "
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   891
     |s|
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   892
     s := ReadStream on:'hello world'.
16209
f2d1d7b2d649 class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 16195
diff changeset
   893
     Transcript show:'<'; show:(s upToAll_positionBefore:'xx'); showCR:'>'. 
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   894
     Transcript showCR:s atEnd.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   895
     Transcript show:'<'; show:(s upToEnd); showCR:'>'. 
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   896
    "
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   897
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   898
    "Modified: / 12.1.1998 / 22:06:42 / cg"
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   899
    "Created: / 12.1.1998 / 22:07:01 / cg"
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   900
! !
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   901
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   902
!PositionableStream methodsFor:'testing'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   903
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   904
atEnd
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   905
    "return true, if the read-position is at the end"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   906
15357
10a1cd767648 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15353
diff changeset
   907
    ^ position >= readLimit
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   908
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   909
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   910
isEmpty
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   911
    "return true, if the contents of the stream is empty"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   912
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   913
    ^ readLimit == 0
9006
e5509951529d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 9003
diff changeset
   914
!
e5509951529d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 9003
diff changeset
   915
10577
3a97ef89ffb1 +isInternalByteStream
Claus Gittinger <cg@exept.de>
parents: 10357
diff changeset
   916
isInternalByteStream
3a97ef89ffb1 +isInternalByteStream
Claus Gittinger <cg@exept.de>
parents: 10357
diff changeset
   917
    "return true, if the stream is an internal stream reading bytes"
3a97ef89ffb1 +isInternalByteStream
Claus Gittinger <cg@exept.de>
parents: 10357
diff changeset
   918
3a97ef89ffb1 +isInternalByteStream
Claus Gittinger <cg@exept.de>
parents: 10357
diff changeset
   919
    ^ collection class isBytes
3a97ef89ffb1 +isInternalByteStream
Claus Gittinger <cg@exept.de>
parents: 10357
diff changeset
   920
3a97ef89ffb1 +isInternalByteStream
Claus Gittinger <cg@exept.de>
parents: 10357
diff changeset
   921
    "Created: / 30-05-2007 / 16:16:12 / cg"
3a97ef89ffb1 +isInternalByteStream
Claus Gittinger <cg@exept.de>
parents: 10357
diff changeset
   922
!
3a97ef89ffb1 +isInternalByteStream
Claus Gittinger <cg@exept.de>
parents: 10357
diff changeset
   923
9006
e5509951529d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 9003
diff changeset
   924
isPositionable
e5509951529d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 9003
diff changeset
   925
    "return true, if the stream supports positioning (this one is)"
e5509951529d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 9003
diff changeset
   926
e5509951529d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 9003
diff changeset
   927
    ^ true
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   928
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   929
1897
22d1ce9b62a4 fixes for packageQuery
Claus Gittinger <cg@exept.de>
parents: 1489
diff changeset
   930
!PositionableStream class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   931
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   932
version
19403
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   933
    ^ '$Header$'
13379
a4644dee3177 changed: #on:
sr
parents: 11434
diff changeset
   934
!
a4644dee3177 changed: #on:
sr
parents: 11434
diff changeset
   935
a4644dee3177 changed: #on:
sr
parents: 11434
diff changeset
   936
version_CVS
19403
5accf347c2c1 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 17611
diff changeset
   937
    ^ '$Header$'
18260
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   938
!
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   939
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   940
version_HG
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   941
e55af242e134 Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18120
diff changeset
   942
    ^ '$Changeset: <not expanded> $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   943
! !
6777
5efddf5358b2 currentFileInDirectory query
Claus Gittinger <cg@exept.de>
parents: 6707
diff changeset
   944
14934
5e273cddded7 setCollection: moved
Claus Gittinger <cg@exept.de>
parents: 13379
diff changeset
   945
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   946
PositionableStream initialize!