author | Stefan Vogel <sv@exept.de> |
Tue, 05 Jun 2007 17:57:48 +0200 | |
changeset 10598 | 75ba1ed5a12b |
parent 10597 | 2ce737e46648 |
child 10599 | 0658b3c147db |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
202 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
5810 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
1 | 14 |
PositionableStream subclass:#ReadStream |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
15 |
instanceVariableNames:'' |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
16 |
classVariableNames:'' |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
17 |
poolDictionaries:'' |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
18 |
category:'Streams' |
1 | 19 |
! |
20 |
||
2162
7e1601f633b6
ff is a separator too (in #skipSeparators*)
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
21 |
!ReadStream class methodsFor:'documentation'! |
88 | 22 |
|
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
202 | 26 |
All Rights Reserved |
1 | 27 |
|
88 | 28 |
This software is furnished under a license and may be used |
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
1 | 36 |
|
88 | 37 |
documentation |
38 |
" |
|
39 |
ReadStream defines protocol for reading streamwise over collections. |
|
1295 | 40 |
|
41 |
[author:] |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
42 |
Claus Gittinger |
1295 | 43 |
|
88 | 44 |
" |
45 |
! ! |
|
1 | 46 |
|
9305
6836bc44f3c3
warn when ReadStream with: is used.
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
47 |
!ReadStream class methodsFor:'blocked instance creation'! |
6836bc44f3c3
warn when ReadStream with: is used.
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
48 |
|
6836bc44f3c3
warn when ReadStream with: is used.
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
49 |
with:aCollection |
9458
ea81e322a954
off-by-one error in #nextBytes:into:startingAt:
Stefan Vogel <sv@exept.de>
parents:
9457
diff
changeset
|
50 |
"with on readStream makes no sense |
ea81e322a954
off-by-one error in #nextBytes:into:startingAt:
Stefan Vogel <sv@exept.de>
parents:
9457
diff
changeset
|
51 |
- what do you want to read from the end of a collection?" |
ea81e322a954
off-by-one error in #nextBytes:into:startingAt:
Stefan Vogel <sv@exept.de>
parents:
9457
diff
changeset
|
52 |
<resource:#obsolete> |
ea81e322a954
off-by-one error in #nextBytes:into:startingAt:
Stefan Vogel <sv@exept.de>
parents:
9457
diff
changeset
|
53 |
|
ea81e322a954
off-by-one error in #nextBytes:into:startingAt:
Stefan Vogel <sv@exept.de>
parents:
9457
diff
changeset
|
54 |
self obsoleteMethodWarning:'WARNING: with: should not be used for ReadStreams - use #on:'. |
9305
6836bc44f3c3
warn when ReadStream with: is used.
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
55 |
^ super with:aCollection |
6836bc44f3c3
warn when ReadStream with: is used.
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
56 |
! ! |
8987
b0d7be646112
#nextBytes:into:startingAt: now works, when fetching into a bit array.
Stefan Vogel <sv@exept.de>
parents:
8914
diff
changeset
|
57 |
|
9458
ea81e322a954
off-by-one error in #nextBytes:into:startingAt:
Stefan Vogel <sv@exept.de>
parents:
9457
diff
changeset
|
58 |
|
202 | 59 |
!ReadStream methodsFor:'converting'! |
60 |
||
61 |
readStream |
|
62 |
"return a readStream from the receiver. Since this is already |
|
63 |
a readStream, return self." |
|
64 |
||
65 |
^ self |
|
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8098
diff
changeset
|
66 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8098
diff
changeset
|
67 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8098
diff
changeset
|
68 |
readStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8098
diff
changeset
|
69 |
"return a readStream from the receiver. Since this is already |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8098
diff
changeset
|
70 |
a readStream, return self. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8098
diff
changeset
|
71 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8098
diff
changeset
|
72 |
This method has been defined for protocol copmatibility with Filename" |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8098
diff
changeset
|
73 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8098
diff
changeset
|
74 |
^ self |
202 | 75 |
! ! |
76 |
||
1400 | 77 |
!ReadStream methodsFor:'emphasis'! |
78 |
||
79 |
emphasis |
|
80 |
"return the emphasis of the current (i.e. next returned by #next) |
|
81 |
element. Streams on a string will return nil for all elements. |
|
82 |
Streams on collections which nothing at all about emphasises, |
|
83 |
will report an error." |
|
84 |
||
7114 | 85 |
^ collection emphasisAt:(position - ZeroPosition + 1). |
1400 | 86 |
|
87 |
" |
|
88 |
|t s| |
|
89 |
||
90 |
t := 'hello world' asText |
|
7114 | 91 |
emphasizeFrom:1 to:5 with:#bold; |
92 |
emphasizeFrom:7 to:11 with:#italic. |
|
1400 | 93 |
|
94 |
s := t readStream. |
|
95 |
[s atEnd] whileFalse:[ |
|
7114 | 96 |
Transcript show:(s emphasis); show:' '. |
97 |
Transcript show:''''; show:(s next); showCR:''''. |
|
1400 | 98 |
]. |
99 |
" |
|
100 |
||
101 |
"Modified: 15.5.1996 / 17:30:33 / cg" |
|
102 |
! ! |
|
103 |
||
345 | 104 |
!ReadStream methodsFor:'queries'! |
105 |
||
5310 | 106 |
copyFrom:beginning to:end |
107 |
^ collection copyFrom:beginning to:end |
|
108 |
! |
|
109 |
||
345 | 110 |
isReadable |
2997 | 111 |
"return true, if reading is supported by the recevier. |
112 |
Here, true is always returned." |
|
113 |
||
345 | 114 |
^ true |
2997 | 115 |
|
116 |
"Modified: 4.10.1997 / 17:59:21 / cg" |
|
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
117 |
! |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
118 |
|
6315 | 119 |
isWritable |
120 |
"return true, if writing is supported by the recevier. |
|
121 |
This has to be redefined in concrete subclasses." |
|
122 |
||
123 |
^ false |
|
124 |
! |
|
125 |
||
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
126 |
size |
2997 | 127 |
"return the number of elements in the streamed collection." |
128 |
||
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
129 |
^ collection size |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
130 |
|
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
131 |
"Created: 13.9.1996 / 18:14:35 / cg" |
2997 | 132 |
"Modified: 4.10.1997 / 17:59:45 / cg" |
345 | 133 |
! ! |
134 |
||
59 | 135 |
!ReadStream methodsFor:'reading'! |
1 | 136 |
|
137 |
next |
|
138 |
"return the next element; advance read pointer. |
|
2 | 139 |
return nil, if there is no next element. |
345 | 140 |
- tuned for a bit more speed on String/ByteArray/Array-Streams" |
1 | 141 |
|
142 |
|ret| |
|
143 |
||
144 |
%{ /* NOCONTEXT */ |
|
145 |
||
146 |
REGISTER int pos; |
|
147 |
unsigned ch; |
|
252 | 148 |
OBJ coll, p, l; |
1 | 149 |
|
1133 | 150 |
coll = __INST(collection); |
151 |
p = __INST(position); |
|
152 |
l = __INST(readLimit); |
|
1 | 153 |
|
252 | 154 |
if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
155 |
||
8098
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
156 |
pos = __intVal(p); |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
157 |
/* make 1-based */ |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
158 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
159 |
if (pos > 0 && pos <= __intVal(l)) { |
8614 | 160 |
OBJ cls, ret; |
59 | 161 |
|
8098
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
162 |
cls = __qClass(coll); |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
163 |
if (cls == @global(String)) { |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
164 |
if (pos <= __stringSize(coll)) { |
8614 | 165 |
ch = __stringVal(coll)[pos-1]; |
166 |
ret = __MKCHARACTER(ch); |
|
8913 | 167 |
__INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
8614 | 168 |
RETURN ( ret ); |
8098
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
169 |
} |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
170 |
} else if (cls == @global(ByteArray)) { |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
171 |
if (pos <= __byteArraySize(coll)) { |
8614 | 172 |
ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
8913 | 173 |
ret = __mkSmallInteger(ch); |
174 |
__INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
|
8614 | 175 |
RETURN ( ret ); |
8098
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
176 |
} |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
177 |
} else if (cls == @global(Unicode16String)) { |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
178 |
if (pos <= __unicode16StringSize(coll)) { |
8614 | 179 |
ch = __Unicode16StringInstPtr(coll)->s_element[pos-1]; |
180 |
ret = __MKUCHARACTER(ch); |
|
8913 | 181 |
__INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
8614 | 182 |
RETURN ( ret ); |
8098
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
183 |
} |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
184 |
} else if (cls == @global(Array)) { |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
185 |
if (pos <= __arraySize(coll)) { |
8614 | 186 |
ret = __ArrayInstPtr(coll)->a_element[pos-1]; |
8913 | 187 |
__INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
8614 | 188 |
RETURN ( ret ); |
8098
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
189 |
} |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
190 |
} |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
191 |
} |
1 | 192 |
} |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
193 |
%}. |
8614 | 194 |
((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEndRead]. |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
195 |
ret := collection at:(position + 1 - ZeroPosition). |
1 | 196 |
position := position + 1. |
197 |
^ ret |
|
198 |
! |
|
199 |
||
252 | 200 |
nextAlphaNumericWord |
1 | 201 |
"read the next word (i.e. up to non letter-or-digit). |
202 |
return a string containing those characters. |
|
3112
ccf7121ddae8
nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents:
2997
diff
changeset
|
203 |
Skips any non-alphanumeric chars first. |
59 | 204 |
- tuned for speed on String-Streams for faster scanning" |
1 | 205 |
%{ |
206 |
/* speedup, if collection is a string */ |
|
207 |
||
208 |
int pos, limit, sz; |
|
209 |
int len; |
|
13 | 210 |
char buffer[256]; |
211 |
REGISTER unsigned char *cp; |
|
212 |
REGISTER unsigned ch; |
|
252 | 213 |
OBJ coll, p, l; |
1 | 214 |
|
1133 | 215 |
coll = __INST(collection); |
216 |
p = __INST(position); |
|
217 |
l = __INST(readLimit); |
|
252 | 218 |
|
219 |
if (__isString(coll) && __bothSmallInteger(p, l)) { |
|
220 |
||
1133 | 221 |
pos = __intVal(p); |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
222 |
/* make 1-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
223 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
224 |
|
1133 | 225 |
limit = __intVal(l); |
329 | 226 |
sz = __qSize(coll) - OHDR_SIZE; |
202 | 227 |
if (sz < limit) |
228 |
limit = sz; |
|
1133 | 229 |
cp = __stringVal(coll) + pos - 1; |
1 | 230 |
|
202 | 231 |
for (;;) { |
232 |
if (pos > limit) break; |
|
233 |
ch = *cp; |
|
1 | 234 |
|
3112
ccf7121ddae8
nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents:
2997
diff
changeset
|
235 |
if (((ch >= 'a') && (ch <= 'z')) || |
ccf7121ddae8
nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents:
2997
diff
changeset
|
236 |
((ch >= 'A') && (ch <= 'Z')) || |
ccf7121ddae8
nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents:
2997
diff
changeset
|
237 |
((ch >= '0') && (ch <= '9'))) |
ccf7121ddae8
nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents:
2997
diff
changeset
|
238 |
break; |
202 | 239 |
cp++; |
240 |
pos++; |
|
241 |
} |
|
1 | 242 |
|
202 | 243 |
len = 0; |
244 |
for (;;) { |
|
245 |
if (pos > limit) break; |
|
246 |
ch = *cp & 0xFF; |
|
1 | 247 |
|
202 | 248 |
if (! (((ch >= 'a') && (ch <= 'z')) || |
249 |
((ch >= 'A') && (ch <= 'Z')) || |
|
250 |
((ch >= '0') && (ch <= '9')))) |
|
251 |
break; |
|
252 |
buffer[len++] = ch; |
|
253 |
if (len >= (sizeof(buffer)-1)) { |
|
254 |
/* emergency */ |
|
255 |
break; |
|
256 |
} |
|
257 |
pos++; |
|
258 |
cp++; |
|
259 |
} |
|
1 | 260 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
261 |
/* make ZeroPosition-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
262 |
pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
8913 | 263 |
__INST(position) = __mkSmallInteger(pos); |
202 | 264 |
buffer[len] = '\0'; |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1665
diff
changeset
|
265 |
RETURN ( (len != 0) ? __MKSTRING_L(buffer, len) : nil ); |
1 | 266 |
} |
267 |
%} |
|
268 |
. |
|
252 | 269 |
^ super nextAlphaNumericWord |
1 | 270 |
! |
271 |
||
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
272 |
nextByte |
4826
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
273 |
"return the next element; advance read pointer. |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
274 |
return nil, if there is no next element. |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
275 |
- tuned for a bit more speed on String/ByteArray/Array-Streams" |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
276 |
|
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
277 |
|ret| |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
278 |
|
4826
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
279 |
%{ /* NOCONTEXT */ |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
280 |
|
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
281 |
REGISTER int pos; |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
282 |
unsigned ch; |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
283 |
OBJ coll, p, l; |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
284 |
|
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
285 |
coll = __INST(collection); |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
286 |
p = __INST(position); |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
287 |
l = __INST(readLimit); |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
288 |
|
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
289 |
if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
290 |
|
8098
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
291 |
pos = __intVal(p); |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
292 |
/* make 1-based */ |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
293 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
294 |
if (pos > 0 && pos <= __intVal(l)) { |
8614 | 295 |
OBJ cls, ret; |
4826
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
296 |
|
8098
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
297 |
cls = __qClass(coll); |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
298 |
if (cls == @global(String)) { |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
299 |
if (pos <= __stringSize(coll)) { |
8614 | 300 |
ch = __stringVal(coll)[pos-1]; |
8913 | 301 |
ret = __mkSmallInteger(ch); |
302 |
__INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
|
8614 | 303 |
RETURN ( ret ); |
8098
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
304 |
} |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
305 |
} else if (cls == @global(ByteArray)) { |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
306 |
if (pos <= __byteArraySize(coll)) { |
8614 | 307 |
ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
8913 | 308 |
ret = __mkSmallInteger(ch); |
309 |
__INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
|
8614 | 310 |
RETURN ( ret ); |
8098
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
311 |
} |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
312 |
} else if (cls == @global(Array)) { |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
313 |
if (pos <= __arraySize(coll)) { |
8614 | 314 |
ret = __ArrayInstPtr(coll)->a_element[pos-1]; |
8913 | 315 |
__INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
8614 | 316 |
RETURN ( ret ); |
8098
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
317 |
} |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
318 |
} |
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
319 |
} |
4826
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
320 |
} |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
321 |
%}. |
8614 | 322 |
((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEndRead]. |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
323 |
ret := collection at:(position + 1 -ZeroPosition). |
4826
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
324 |
position := position + 1. |
8098
8d1d5cd8529b
nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents:
7483
diff
changeset
|
325 |
^ ret asInteger |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
326 |
! |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
327 |
|
8530
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
328 |
nextBytes:numBytes into:aCollection startingAt:initialIndex |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
329 |
"return the next numBytes from the stream. If the end is |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
330 |
reached before, only that many bytes are copyied into the |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
331 |
collection. |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
332 |
Returns the number of bytes that have been actually read. |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
333 |
The receiver must support reading of binary bytes. |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
334 |
|
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
335 |
Notice: this method is provided here for protocol completeness |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
336 |
with externalStreams - it is normally not used with other |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
337 |
streams." |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
338 |
|
9458
ea81e322a954
off-by-one error in #nextBytes:into:startingAt:
Stefan Vogel <sv@exept.de>
parents:
9457
diff
changeset
|
339 |
((initialIndex + numBytes - 1) <= aCollection size |
ea81e322a954
off-by-one error in #nextBytes:into:startingAt:
Stefan Vogel <sv@exept.de>
parents:
9457
diff
changeset
|
340 |
and:[(position + numBytes) <= readLimit |
ea81e322a954
off-by-one error in #nextBytes:into:startingAt:
Stefan Vogel <sv@exept.de>
parents:
9457
diff
changeset
|
341 |
and:[collection isByteCollection |
ea81e322a954
off-by-one error in #nextBytes:into:startingAt:
Stefan Vogel <sv@exept.de>
parents:
9457
diff
changeset
|
342 |
and:[aCollection isByteCollection |
ea81e322a954
off-by-one error in #nextBytes:into:startingAt:
Stefan Vogel <sv@exept.de>
parents:
9457
diff
changeset
|
343 |
]]]) ifTrue:[ |
ea81e322a954
off-by-one error in #nextBytes:into:startingAt:
Stefan Vogel <sv@exept.de>
parents:
9457
diff
changeset
|
344 |
"do it the fast way" |
ea81e322a954
off-by-one error in #nextBytes:into:startingAt:
Stefan Vogel <sv@exept.de>
parents:
9457
diff
changeset
|
345 |
aCollection |
ea81e322a954
off-by-one error in #nextBytes:into:startingAt:
Stefan Vogel <sv@exept.de>
parents:
9457
diff
changeset
|
346 |
replaceBytesFrom:initialIndex to:(initialIndex + numBytes - 1) |
ea81e322a954
off-by-one error in #nextBytes:into:startingAt:
Stefan Vogel <sv@exept.de>
parents:
9457
diff
changeset
|
347 |
with:collection startingAt:position+1. |
ea81e322a954
off-by-one error in #nextBytes:into:startingAt:
Stefan Vogel <sv@exept.de>
parents:
9457
diff
changeset
|
348 |
position := position + numBytes. |
ea81e322a954
off-by-one error in #nextBytes:into:startingAt:
Stefan Vogel <sv@exept.de>
parents:
9457
diff
changeset
|
349 |
^ numBytes |
8530
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
350 |
]. |
9458
ea81e322a954
off-by-one error in #nextBytes:into:startingAt:
Stefan Vogel <sv@exept.de>
parents:
9457
diff
changeset
|
351 |
"do it the hard way" |
8530
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
352 |
^ super nextBytes:numBytes into:aCollection startingAt:initialIndex |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
353 |
|
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
354 |
" |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
355 |
|s n buffer| |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
356 |
|
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
357 |
buffer := ByteArray new:10. |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
358 |
|
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
359 |
s := ReadStream on:#[1 2 3 4 5 6 7 8 9]. |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
360 |
s next:3. |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
361 |
n := s nextBytes:9 into:buffer startingAt:1. |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
362 |
Transcript showCR:('n = %1; buffer = <%2>' bindWith:n with:buffer) |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
363 |
" |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
364 |
! |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
365 |
|
611 | 366 |
nextDecimalInteger |
367 |
"read the next integer in radix 10. dont skip whitespace. |
|
368 |
- tuned for speed on String-Streams for faster scanning" |
|
369 |
||
370 |
|value nextOne| |
|
371 |
%{ |
|
372 |
int pos, limit, sz; |
|
373 |
REGISTER unsigned char *cp; |
|
374 |
REGISTER unsigned ch; |
|
8914 | 375 |
INT val = 0; |
611 | 376 |
OBJ coll, p, l; |
377 |
||
1133 | 378 |
coll = __INST(collection); |
379 |
p = __INST(position); |
|
380 |
l = __INST(readLimit); |
|
611 | 381 |
|
382 |
if (__isString(coll) && __bothSmallInteger(p, l)) { |
|
383 |
||
1133 | 384 |
pos = __intVal(p); |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
385 |
/* make 1-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
386 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
1133 | 387 |
limit = __intVal(l); |
611 | 388 |
sz = __qSize(coll) - OHDR_SIZE; |
389 |
if (sz < limit) |
|
390 |
limit = sz; |
|
1133 | 391 |
cp = __stringVal(coll) + pos - 1; |
611 | 392 |
|
393 |
for (;;) { |
|
394 |
if (pos > limit) break; |
|
395 |
ch = *cp; |
|
396 |
||
397 |
if ((ch < '0') || (ch > '9')) break; |
|
398 |
val = val * 10 + (ch - '0'); |
|
399 |
pos++; |
|
400 |
if (val > (_MAX_INT / 10)) goto oops; |
|
401 |
cp++; |
|
402 |
} |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
403 |
/* make ZeroPosition-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
404 |
pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
8913 | 405 |
__INST(position) = __mkSmallInteger(pos); |
406 |
RETURN (__mkSmallInteger(val)); |
|
611 | 407 |
} |
408 |
oops: |
|
8913 | 409 |
value = __mkSmallInteger(val); |
611 | 410 |
%} |
411 |
. |
|
412 |
"fall-back for non-string streams - we have to continue where |
|
413 |
above primitive left off, in case of a large integer ... |
|
414 |
(instead of doing a super nextDecimalInteger)" |
|
415 |
||
416 |
nextOne := self peek. |
|
417 |
[nextOne notNil and:[nextOne isDigitRadix:10]] whileTrue:[ |
|
418 |
value = (value * 10) + nextOne digitValue. |
|
419 |
nextOne := self nextPeek |
|
420 |
]. |
|
421 |
^ value |
|
422 |
! |
|
423 |
||
9457 | 424 |
nextOrNil |
425 |
"return the next element; advance read pointer. |
|
426 |
return nil, if there is no next element. |
|
427 |
- tuned for a bit more speed on String/ByteArray/Array-Streams" |
|
428 |
||
429 |
|ret| |
|
430 |
||
431 |
%{ /* NOCONTEXT */ |
|
432 |
||
433 |
REGISTER int pos; |
|
434 |
unsigned ch; |
|
435 |
OBJ coll, p, l; |
|
436 |
||
437 |
coll = __INST(collection); |
|
438 |
p = __INST(position); |
|
439 |
l = __INST(readLimit); |
|
440 |
||
441 |
if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
|
442 |
pos = __intVal(p); |
|
443 |
/* make 1-based */ |
|
444 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
|
445 |
if (pos > 0) { |
|
446 |
OBJ cls, ret; |
|
447 |
||
448 |
if (pos > __intVal(l)) { |
|
449 |
RETURN(nil); |
|
450 |
} |
|
451 |
||
452 |
cls = __qClass(coll); |
|
453 |
if (cls == @global(String)) { |
|
454 |
if (pos <= __stringSize(coll)) { |
|
455 |
ch = __stringVal(coll)[pos-1]; |
|
456 |
ret = __MKCHARACTER(ch); |
|
457 |
__INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
|
458 |
RETURN ( ret ); |
|
459 |
} |
|
460 |
} else if (cls == @global(ByteArray)) { |
|
461 |
if (pos <= __byteArraySize(coll)) { |
|
462 |
ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
|
463 |
ret = __mkSmallInteger(ch); |
|
464 |
__INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
|
465 |
RETURN ( ret ); |
|
466 |
} |
|
467 |
} else if (cls == @global(Unicode16String)) { |
|
468 |
if (pos <= __unicode16StringSize(coll)) { |
|
469 |
ch = __Unicode16StringInstPtr(coll)->s_element[pos-1]; |
|
470 |
ret = __MKUCHARACTER(ch); |
|
471 |
__INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
|
472 |
RETURN ( ret ); |
|
473 |
} |
|
474 |
} else if (cls == @global(Array)) { |
|
475 |
if (pos <= __arraySize(coll)) { |
|
476 |
ret = __ArrayInstPtr(coll)->a_element[pos-1]; |
|
477 |
__INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
|
478 |
RETURN ( ret ); |
|
479 |
} |
|
480 |
} |
|
481 |
} |
|
482 |
} |
|
483 |
%}. |
|
484 |
ret := collection at:(position + 1 - ZeroPosition). |
|
485 |
position := position + 1. |
|
486 |
^ ret |
|
487 |
! |
|
488 |
||
611 | 489 |
nextPeek |
490 |
"advance read pointer return the peek element. |
|
491 |
this is equivalent to (self next; peek). |
|
492 |
- tuned for speed on String-Streams for faster scanning" |
|
493 |
||
494 |
%{ /* NOCONTEXT */ |
|
495 |
OBJ coll, l, p; |
|
496 |
||
1133 | 497 |
coll = __INST(collection); |
498 |
p = __INST(position); |
|
499 |
l = __INST(readLimit); |
|
611 | 500 |
|
501 |
if (__isString(coll) && __bothSmallInteger(p, l)) { |
|
8614 | 502 |
REGISTER int pos; |
503 |
unsigned ch; |
|
611 | 504 |
|
8614 | 505 |
pos = __intVal(p); |
506 |
/* make 1-based */ |
|
507 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
|
508 |
if ((pos > 0) && (pos < __intVal(l)) && (pos < __stringSize(coll))) { |
|
509 |
pos = pos + 1; |
|
510 |
ch = __stringVal(coll)[pos-1]; |
|
511 |
/* make ZeroPosition-based */ |
|
512 |
pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
|
8913 | 513 |
__INST(position) = __mkSmallInteger(pos); |
8614 | 514 |
RETURN ( __MKCHARACTER(ch) ); |
515 |
} |
|
611 | 516 |
} |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
517 |
%}. |
8614 | 518 |
((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEndRead]. |
611 | 519 |
position := position + 1. |
8614 | 520 |
((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEndRead]. |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
521 |
^ collection at:(position + 1 - ZeroPosition) |
611 | 522 |
! |
523 |
||
524 |
peek |
|
525 |
"return the next element; do NOT advance read pointer. |
|
526 |
return nil, if there is no next element. |
|
527 |
- tuned for a bit more speed on String/ByteArray/Array-Streams" |
|
1 | 528 |
|
529 |
%{ /* NOCONTEXT */ |
|
611 | 530 |
|
531 |
REGISTER int pos; |
|
532 |
unsigned ch; |
|
533 |
OBJ coll; |
|
534 |
OBJ cls, p, l; |
|
1 | 535 |
|
1133 | 536 |
coll = __INST(collection); |
537 |
p = __INST(position); |
|
538 |
l = __INST(readLimit); |
|
252 | 539 |
|
611 | 540 |
if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
1 | 541 |
|
8614 | 542 |
pos = __intVal(p); |
543 |
/* make 1-based */ |
|
544 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
|
545 |
if (pos <= __intVal(l) && pos > 0) { |
|
546 |
cls = __qClass(coll); |
|
547 |
if (cls == @global(String)) { |
|
548 |
if (pos <= __stringSize(coll)) { |
|
549 |
ch = __stringVal(coll)[pos-1]; |
|
550 |
RETURN ( __MKCHARACTER(ch) ); |
|
551 |
} |
|
552 |
} else if (cls == @global(ByteArray)) { |
|
553 |
if (pos <= __byteArraySize(coll)) { |
|
554 |
ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
|
8913 | 555 |
RETURN ( __mkSmallInteger(ch) ); |
8614 | 556 |
} |
557 |
} else if (cls == @global(Array)) { |
|
558 |
if (pos <= __arraySize(coll)) { |
|
559 |
RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]); |
|
560 |
} |
|
561 |
} |
|
562 |
} |
|
1 | 563 |
} |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
564 |
%}. |
8614 | 565 |
((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEndRead]. |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
566 |
^ collection at:(position + 1 - ZeroPosition) |
1 | 567 |
! |
568 |
||
3316 | 569 |
peekOrNil |
570 |
"return the next element; do NOT advance read pointer. |
|
571 |
return nil, if there is no next element. |
|
572 |
This is much like #peek - |
|
573 |
However, unlike #peek, this does not raise an atEnd-query signal - even |
|
574 |
if handled. Instead, nil is returned immediately." |
|
575 |
||
576 |
%{ /* NOCONTEXT */ |
|
577 |
||
578 |
REGISTER int pos; |
|
579 |
unsigned ch; |
|
580 |
OBJ coll; |
|
581 |
OBJ cls, p, l; |
|
582 |
||
583 |
coll = __INST(collection); |
|
584 |
p = __INST(position); |
|
585 |
l = __INST(readLimit); |
|
586 |
||
587 |
if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
|
588 |
||
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
589 |
pos = __intVal(p); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
590 |
/* make 1-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
591 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
592 |
if (pos <= __intVal(l) && pos > 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
593 |
cls = __qClass(coll); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
594 |
if (cls == @global(String)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
595 |
if (pos <= __stringSize(coll)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
596 |
ch = __stringVal(coll)[pos-1]; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
597 |
RETURN ( __MKCHARACTER(ch) ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
598 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
599 |
RETURN ( nil ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
600 |
} else if (cls == @global(ByteArray)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
601 |
if (pos <= __byteArraySize(coll)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
602 |
ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
8913 | 603 |
RETURN ( __mkSmallInteger(ch) ); |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
604 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
605 |
RETURN ( nil ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
606 |
} else if (cls == @global(Array)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
607 |
if (pos <= __arraySize(coll)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
608 |
RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
609 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
610 |
RETURN ( nil ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
611 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
612 |
} |
3316 | 613 |
} |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
614 |
%}. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
615 |
((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ nil]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
616 |
^ collection at:(position + 1 - ZeroPosition) |
3316 | 617 |
! |
618 |
||
1 | 619 |
skipSeparators |
620 |
"skip all whitespace; next will return next non-white-space element. |
|
59 | 621 |
Return the peeked character or nil, if the end-of-stream was reached. |
2 | 622 |
- reimplemented for speed on String-Streams for faster scanning" |
1 | 623 |
|
624 |
%{ /* NOCONTEXT */ |
|
252 | 625 |
OBJ coll, p, l; |
1 | 626 |
|
1133 | 627 |
coll = __INST(collection); |
628 |
p = __INST(position); |
|
629 |
l = __INST(readLimit); |
|
252 | 630 |
|
631 |
if (__isString(coll) && __bothSmallInteger(p, l)) { |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
632 |
REGISTER unsigned char *chars; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
633 |
REGISTER unsigned ch; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
634 |
REGISTER int pos; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
635 |
int limit; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
636 |
int sz; |
1 | 637 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
638 |
pos = __intVal(p); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
639 |
/* make 1-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
640 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
641 |
if (pos <= 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
642 |
RETURN ( nil ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
643 |
} |
1 | 644 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
645 |
limit = __intVal(l); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
646 |
sz = __qSize(coll) - OHDR_SIZE; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
647 |
if (limit > sz) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
648 |
limit = sz; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
649 |
} |
1 | 650 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
651 |
chars = (unsigned char *)(__stringVal(coll) + pos - 1); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
652 |
while (pos <= limit) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
653 |
pos++; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
654 |
ch = *chars++; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
655 |
if ((ch > 0x20) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
656 |
|| ((ch != ' ') |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
657 |
&& (ch != '\t') |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
658 |
&& (ch != '\r') |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
659 |
&& (ch != '\n') |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
660 |
&& (ch != '\f') |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
661 |
&& (ch != 0x0B))) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
662 |
/* make ZeroPosition-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
663 |
pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
8913 | 664 |
__INST(position) = __mkSmallInteger(pos-1); |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
665 |
RETURN ( __MKCHARACTER(ch) ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
666 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
667 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
668 |
/* make ZeroPosition-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
669 |
pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
8913 | 670 |
__INST(position) = __mkSmallInteger(pos); |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
671 |
RETURN ( nil ); |
1 | 672 |
} |
1406 | 673 |
%}. |
1 | 674 |
^ super skipSeparators |
1406 | 675 |
|
676 |
" |
|
677 |
|s| |
|
678 |
||
679 |
s := ' hello world ' readStream. |
|
680 |
s skipSeparators. |
|
681 |
s next. |
|
682 |
" |
|
1 | 683 |
! |
684 |
||
13 | 685 |
skipSeparatorsExceptCR |
686 |
"skip all whitespace except newlines; |
|
202 | 687 |
next will return next non-white-space element. |
688 |
- reimplemented for speed on String-Streams for faster scanning" |
|
689 |
||
13 | 690 |
%{ /* NOCONTEXT */ |
691 |
||
252 | 692 |
OBJ coll, p, l; |
693 |
||
1133 | 694 |
coll = __INST(collection); |
695 |
p = __INST(position); |
|
696 |
l = __INST(readLimit); |
|
252 | 697 |
|
698 |
if (__isString(coll) && __bothSmallInteger(p, l)) { |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
699 |
REGISTER unsigned char *chars; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
700 |
REGISTER unsigned ch; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
701 |
REGISTER int pos; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
702 |
int limit; |
13 | 703 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
704 |
pos = __intVal(p); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
705 |
/* make 1-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
706 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
707 |
if (pos <= 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
708 |
RETURN ( nil ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
709 |
} |
2162
7e1601f633b6
ff is a separator too (in #skipSeparators*)
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
710 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
711 |
limit = __intVal(l); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
712 |
if (limit > (__qSize(coll) - OHDR_SIZE)) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
713 |
limit = __qSize(coll) - OHDR_SIZE; |
13 | 714 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
715 |
chars = (unsigned char *)(__stringVal(coll) + pos - 1); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
716 |
while (pos <= limit) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
717 |
ch = *chars++; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
718 |
if (((int)ch > 0x20) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
719 |
|| ( |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
720 |
(ch != ' ') |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
721 |
&& (ch != '\t') |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
722 |
&& (ch != '\f') |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
723 |
&& (ch != '\b') |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
724 |
&& (ch != 0x0B))) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
725 |
/* make ZeroPosition-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
726 |
pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
8913 | 727 |
__INST(position) = __mkSmallInteger(pos); |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
728 |
RETURN ( __MKCHARACTER(ch) ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
729 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
730 |
pos++; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
731 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
732 |
/* make ZeroPosition-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
733 |
pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
8913 | 734 |
__INST(position) = __mkSmallInteger(pos); |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
735 |
RETURN ( nil ); |
13 | 736 |
} |
737 |
%} |
|
738 |
. |
|
739 |
^ super skipSeparatorsExceptCR |
|
740 |
! |
|
741 |
||
611 | 742 |
skipThrough:anObject |
6011
3b91d7834ca5
fixed: skipThrough dod not position atEnd if the element was not found.
Claus Gittinger <cg@exept.de>
parents:
5810
diff
changeset
|
743 |
"skip all objects up-to and including anObject. |
3b91d7834ca5
fixed: skipThrough dod not position atEnd if the element was not found.
Claus Gittinger <cg@exept.de>
parents:
5810
diff
changeset
|
744 |
Return the receiver if skip was successful, |
3b91d7834ca5
fixed: skipThrough dod not position atEnd if the element was not found.
Claus Gittinger <cg@exept.de>
parents:
5810
diff
changeset
|
745 |
otherwise (i.e. if not found) return nil and leave the stream positioned at the end. |
611 | 746 |
On success, the next read operation will return the element after anObject. |
747 |
- reimplemented for speed on String-Streams for faster scanning" |
|
748 |
||
749 |
%{ /* NOCONTEXT */ |
|
750 |
OBJ coll, p, l; |
|
751 |
||
1133 | 752 |
coll = __INST(collection); |
753 |
p = __INST(position); |
|
754 |
l = __INST(readLimit); |
|
611 | 755 |
|
756 |
if (__isString(coll) |
|
757 |
&& __isCharacter(anObject) |
|
758 |
&& __bothSmallInteger(p, l)) { |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
759 |
REGISTER unsigned char *chars; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
760 |
REGISTER int pos, limit; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
761 |
unsigned ch; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
762 |
int sz; |
611 | 763 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
764 |
pos = __intVal(p); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
765 |
/* make 1-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
766 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
767 |
if (pos <= 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
768 |
RETURN ( nil ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
769 |
} |
611 | 770 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
771 |
limit = __intVal(l); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
772 |
sz = __stringSize(coll); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
773 |
if (limit > sz) limit = sz; |
611 | 774 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
775 |
chars = (unsigned char *)(__stringVal(coll) + pos - 1); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
776 |
ch = __intVal(_characterVal(anObject)) & 0xFF; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
777 |
while (pos < limit) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
778 |
if (*chars == ch) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
779 |
ch = *++chars; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
780 |
pos++; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
781 |
/* make ZeroPosition-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
782 |
pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
8913 | 783 |
__INST(position) = __mkSmallInteger(pos); |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
784 |
RETURN ( self ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
785 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
786 |
chars++; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
787 |
pos++; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
788 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
789 |
/* make ZeroPosition-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
790 |
pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
8913 | 791 |
__INST(position) = __mkSmallInteger(pos+1); |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
792 |
RETURN ( nil ); |
611 | 793 |
} |
6011
3b91d7834ca5
fixed: skipThrough dod not position atEnd if the element was not found.
Claus Gittinger <cg@exept.de>
parents:
5810
diff
changeset
|
794 |
%}. |
611 | 795 |
^ super skipThrough:anObject |
10597 | 796 |
! |
797 |
||
798 |
upToEnd |
|
799 |
"answer the contents of the stream from the current position up to the end" |
|
800 |
||
10598 | 801 |
|start| |
802 |
||
803 |
start := position + 1 - ZeroPosition. |
|
804 |
(start > readLimit) ifTrue:[^ self pastEndRead]. |
|
805 |
position := readLimit . |
|
806 |
^ collection copyFrom:start to:readLimit. |
|
807 |
||
10597 | 808 |
|
809 |
" |
|
810 |
'1234567890' readStream upToEnd |
|
811 |
#(1 2 3 4 5 6 7 8 9 0) readStream upToEnd |
|
812 |
'1234567890' readStream next; upToEnd |
|
10598 | 813 |
'1234567890' readStream next; upToEnd; next |
10597 | 814 |
" |
1 | 815 |
! ! |
816 |
||
59 | 817 |
!ReadStream methodsFor:'writing'! |
1 | 818 |
|
819 |
nextPut:anElement |
|
10 | 820 |
"catch write access to readstreams - report an error" |
821 |
||
822 |
self shouldNotImplement |
|
1 | 823 |
! ! |
611 | 824 |
|
2162
7e1601f633b6
ff is a separator too (in #skipSeparators*)
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
825 |
!ReadStream class methodsFor:'documentation'! |
701 | 826 |
|
827 |
version |
|
10598 | 828 |
^ '$Header: /cvs/stx/stx/libbasic/ReadStream.st,v 1.61 2007-06-05 15:57:48 stefan Exp $' |
701 | 829 |
! ! |