author | Claus Gittinger <cg@exept.de> |
Sat, 06 Apr 1996 15:23:05 +0200 | |
changeset 1138 | 993e6ffdbf51 |
parent 1133 | 961f2b095c22 |
child 1295 | 83f594f05c52 |
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 |
" |
|
12 |
||
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
13 |
'From Smalltalk/X, Version:2.10.8 on 6-feb-1996 at 15:31:28' ! |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
14 |
|
1 | 15 |
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
|
16 |
instanceVariableNames:'' |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
17 |
classVariableNames:'' |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
18 |
poolDictionaries:'' |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
19 |
category:'Streams' |
1 | 20 |
! |
21 |
||
88 | 22 |
!ReadStream class methodsFor:'documentation'! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
202 | 27 |
All Rights Reserved |
1 | 28 |
|
88 | 29 |
This software is furnished under a license and may be used |
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
1 | 37 |
|
88 | 38 |
documentation |
39 |
" |
|
40 |
ReadStream defines protocol for reading streamwise over collections. |
|
41 |
" |
|
42 |
! ! |
|
1 | 43 |
|
202 | 44 |
!ReadStream methodsFor:'converting'! |
45 |
||
46 |
readStream |
|
47 |
"return a readStream from the receiver. Since this is already |
|
48 |
a readStream, return self." |
|
49 |
||
50 |
^ self |
|
51 |
! ! |
|
52 |
||
345 | 53 |
!ReadStream methodsFor:'queries'! |
54 |
||
55 |
isReadable |
|
56 |
^ true |
|
57 |
! ! |
|
58 |
||
59 | 59 |
!ReadStream methodsFor:'reading'! |
1 | 60 |
|
61 |
next |
|
62 |
"return the next element; advance read pointer. |
|
2 | 63 |
return nil, if there is no next element. |
345 | 64 |
- tuned for a bit more speed on String/ByteArray/Array-Streams" |
1 | 65 |
|
66 |
|ret| |
|
67 |
||
68 |
%{ /* NOCONTEXT */ |
|
69 |
||
70 |
REGISTER int pos; |
|
71 |
unsigned ch; |
|
252 | 72 |
OBJ coll, p, l; |
1 | 73 |
|
1133 | 74 |
coll = __INST(collection); |
75 |
p = __INST(position); |
|
76 |
l = __INST(readLimit); |
|
1 | 77 |
|
252 | 78 |
if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
79 |
||
1133 | 80 |
pos = __intVal(p); |
81 |
if (pos > 0 && pos <= __intVal(l)) { |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
82 |
OBJ cls; |
59 | 83 |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
84 |
cls = __qClass(coll); |
1133 | 85 |
if (cls == @global(String)) { |
86 |
if (pos <= __stringSize(coll)) { |
|
87 |
__INST(position) = __MKSMALLINT(pos + 1); |
|
88 |
ch = __stringVal(coll)[pos-1]; |
|
89 |
RETURN ( __MKCHARACTER(ch) ); |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
90 |
} |
1133 | 91 |
} else if (cls == @global(ByteArray)) { |
92 |
if (pos <= __byteArraySize(coll)) { |
|
93 |
__INST(position) = __MKSMALLINT(pos + 1); |
|
94 |
ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
|
95 |
RETURN ( __MKSMALLINT(ch) ); |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
96 |
} |
1133 | 97 |
} else if (cls == @global(Array)) { |
98 |
if (pos <= __arraySize(coll)) { |
|
99 |
__INST(position) = __MKSMALLINT(pos + 1); |
|
100 |
RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]); |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
101 |
} |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
102 |
} |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
103 |
} |
1 | 104 |
} |
105 |
%} |
|
106 |
. |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
107 |
(position > readLimit) ifTrue:[^ self pastEnd]. |
1 | 108 |
ret := collection at:position. |
109 |
position := position + 1. |
|
110 |
^ ret |
|
111 |
! |
|
112 |
||
252 | 113 |
nextAlphaNumericWord |
1 | 114 |
"read the next word (i.e. up to non letter-or-digit). |
115 |
return a string containing those characters. |
|
59 | 116 |
- tuned for speed on String-Streams for faster scanning" |
1 | 117 |
%{ |
118 |
/* speedup, if collection is a string */ |
|
119 |
||
120 |
int pos, limit, sz; |
|
121 |
int len; |
|
13 | 122 |
char buffer[256]; |
123 |
REGISTER unsigned char *cp; |
|
124 |
REGISTER unsigned ch; |
|
252 | 125 |
OBJ coll, p, l; |
1 | 126 |
|
1133 | 127 |
coll = __INST(collection); |
128 |
p = __INST(position); |
|
129 |
l = __INST(readLimit); |
|
252 | 130 |
|
131 |
if (__isString(coll) && __bothSmallInteger(p, l)) { |
|
132 |
||
1133 | 133 |
pos = __intVal(p); |
134 |
limit = __intVal(l); |
|
329 | 135 |
sz = __qSize(coll) - OHDR_SIZE; |
202 | 136 |
if (sz < limit) |
137 |
limit = sz; |
|
1133 | 138 |
cp = __stringVal(coll) + pos - 1; |
1 | 139 |
|
202 | 140 |
for (;;) { |
141 |
if (pos > limit) break; |
|
142 |
ch = *cp; |
|
1 | 143 |
|
202 | 144 |
if (ch > ' ') break; |
145 |
if ((ch != ' ') && (ch != '\t') && (ch != '\r') |
|
146 |
&& (ch != '\n') && (ch != 0x0b)) break; |
|
147 |
cp++; |
|
148 |
pos++; |
|
149 |
} |
|
1 | 150 |
|
202 | 151 |
len = 0; |
152 |
for (;;) { |
|
153 |
if (pos > limit) break; |
|
154 |
ch = *cp & 0xFF; |
|
1 | 155 |
|
202 | 156 |
if (! (((ch >= 'a') && (ch <= 'z')) || |
157 |
((ch >= 'A') && (ch <= 'Z')) || |
|
158 |
((ch >= '0') && (ch <= '9')))) |
|
159 |
break; |
|
160 |
buffer[len++] = ch; |
|
161 |
if (len >= (sizeof(buffer)-1)) { |
|
162 |
/* emergency */ |
|
163 |
break; |
|
164 |
} |
|
165 |
pos++; |
|
166 |
cp++; |
|
167 |
} |
|
1 | 168 |
|
1133 | 169 |
__INST(position) = __MKSMALLINT(pos); |
202 | 170 |
buffer[len] = '\0'; |
521
70533ec40482
use new MKSTRING_L if length is known (avoids a useless strlen)
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
171 |
RETURN ( (len != 0) ? __MKSTRING_L(buffer, len COMMA_CON) : nil ); |
1 | 172 |
} |
173 |
%} |
|
174 |
. |
|
252 | 175 |
^ super nextAlphaNumericWord |
1 | 176 |
! |
177 |
||
611 | 178 |
nextDecimalInteger |
179 |
"read the next integer in radix 10. dont skip whitespace. |
|
180 |
- tuned for speed on String-Streams for faster scanning" |
|
181 |
||
182 |
|value nextOne| |
|
183 |
%{ |
|
184 |
int pos, limit, sz; |
|
185 |
REGISTER unsigned char *cp; |
|
186 |
REGISTER unsigned ch; |
|
187 |
int val = 0; |
|
188 |
OBJ coll, p, l; |
|
189 |
||
1133 | 190 |
coll = __INST(collection); |
191 |
p = __INST(position); |
|
192 |
l = __INST(readLimit); |
|
611 | 193 |
|
194 |
if (__isString(coll) && __bothSmallInteger(p, l)) { |
|
195 |
||
1133 | 196 |
pos = __intVal(p); |
197 |
limit = __intVal(l); |
|
611 | 198 |
sz = __qSize(coll) - OHDR_SIZE; |
199 |
if (sz < limit) |
|
200 |
limit = sz; |
|
1133 | 201 |
cp = __stringVal(coll) + pos - 1; |
611 | 202 |
|
203 |
for (;;) { |
|
204 |
if (pos > limit) break; |
|
205 |
ch = *cp; |
|
206 |
||
207 |
if ((ch < '0') || (ch > '9')) break; |
|
208 |
val = val * 10 + (ch - '0'); |
|
209 |
pos++; |
|
210 |
if (val > (_MAX_INT / 10)) goto oops; |
|
211 |
cp++; |
|
212 |
} |
|
1133 | 213 |
__INST(position) = __MKSMALLINT(pos); |
214 |
return __MKSMALLINT(val); |
|
611 | 215 |
} |
216 |
oops: |
|
1133 | 217 |
value = __MKSMALLINT(val); |
611 | 218 |
%} |
219 |
. |
|
220 |
"fall-back for non-string streams - we have to continue where |
|
221 |
above primitive left off, in case of a large integer ... |
|
222 |
(instead of doing a super nextDecimalInteger)" |
|
223 |
||
224 |
nextOne := self peek. |
|
225 |
[nextOne notNil and:[nextOne isDigitRadix:10]] whileTrue:[ |
|
226 |
value = (value * 10) + nextOne digitValue. |
|
227 |
nextOne := self nextPeek |
|
228 |
]. |
|
229 |
^ value |
|
230 |
! |
|
231 |
||
232 |
nextPeek |
|
233 |
"advance read pointer return the peek element. |
|
234 |
this is equivalent to (self next; peek). |
|
235 |
- tuned for speed on String-Streams for faster scanning" |
|
236 |
||
237 |
%{ /* NOCONTEXT */ |
|
238 |
OBJ coll, l, p; |
|
239 |
||
1133 | 240 |
coll = __INST(collection); |
241 |
p = __INST(position); |
|
242 |
l = __INST(readLimit); |
|
611 | 243 |
|
244 |
if (__isString(coll) && __bothSmallInteger(p, l)) { |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
245 |
REGISTER int pos; |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
246 |
unsigned ch; |
611 | 247 |
|
1133 | 248 |
pos = __intVal(p); |
249 |
if ((pos > 0) && (pos < __intVal(l)) && (pos < __stringSize(coll))) { |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
250 |
pos += 1; |
1133 | 251 |
__INST(position) = __MKSMALLINT(pos); |
252 |
ch = __stringVal(coll)[pos-1]; |
|
253 |
RETURN ( __MKCHARACTER(ch) ); |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
254 |
} |
611 | 255 |
} |
256 |
%} |
|
257 |
. |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
258 |
(position > readLimit) ifTrue:[^ self pastEnd]. |
611 | 259 |
position := position + 1. |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
260 |
(position > readLimit) ifTrue:[^ self pastEnd]. |
611 | 261 |
^ collection at:position |
262 |
! |
|
263 |
||
1 | 264 |
nextSymbol |
265 |
"read the next selector-symbol (i.e. up to non letter-or-digit). |
|
266 |
return a string containing those characters. |
|
59 | 267 |
- tuned for speed on String-Streams for faster scanning" |
1 | 268 |
%{ |
269 |
int pos, limit, sz; |
|
270 |
int len; |
|
13 | 271 |
char buffer[256]; |
272 |
REGISTER unsigned char *cp; |
|
273 |
REGISTER unsigned ch; |
|
252 | 274 |
OBJ coll, p, l; |
1 | 275 |
|
1133 | 276 |
coll = __INST(collection); |
277 |
p = __INST(position); |
|
278 |
l = __INST(readLimit); |
|
252 | 279 |
|
280 |
if (__isString(coll) && __bothSmallInteger(p, l)) { |
|
281 |
||
1133 | 282 |
pos = __intVal(p); |
283 |
limit = __intVal(l); |
|
329 | 284 |
sz = __qSize(coll) - OHDR_SIZE; |
202 | 285 |
if (sz < limit) |
286 |
limit = sz; |
|
1133 | 287 |
cp = __stringVal(coll) + pos - 1; |
1 | 288 |
|
202 | 289 |
len = 0; |
290 |
for (;;) { |
|
291 |
if (pos > limit) break; |
|
292 |
ch = *cp; |
|
1 | 293 |
|
202 | 294 |
if (! (((ch >= 'a') && (ch <= 'z')) || |
295 |
((ch >= 'A') && (ch <= 'Z')) || |
|
296 |
((ch >= '0') && (ch <= '9')) || |
|
297 |
(ch == ':'))) |
|
298 |
break; |
|
299 |
buffer[len++] = ch; |
|
300 |
if (len >= (sizeof(buffer)-1)) { |
|
301 |
/* emergency */ |
|
302 |
break; |
|
303 |
} |
|
304 |
pos++; |
|
305 |
cp++; |
|
306 |
} |
|
1 | 307 |
|
1133 | 308 |
__INST(position) = __MKSMALLINT(pos); |
202 | 309 |
buffer[len] = '\0'; |
521
70533ec40482
use new MKSTRING_L if length is known (avoids a useless strlen)
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
310 |
RETURN ( (len != 0) ? __MKSTRING_L(buffer, len COMMA_CON) : nil ); |
1 | 311 |
} |
312 |
%} |
|
313 |
. |
|
314 |
^ super nextSymbol |
|
315 |
! |
|
316 |
||
611 | 317 |
peek |
318 |
"return the next element; do NOT advance read pointer. |
|
319 |
return nil, if there is no next element. |
|
320 |
- tuned for a bit more speed on String/ByteArray/Array-Streams" |
|
1 | 321 |
|
322 |
%{ /* NOCONTEXT */ |
|
611 | 323 |
|
324 |
REGISTER int pos; |
|
325 |
unsigned ch; |
|
326 |
OBJ coll; |
|
327 |
OBJ cls, p, l; |
|
1 | 328 |
|
1133 | 329 |
coll = __INST(collection); |
330 |
p = __INST(position); |
|
331 |
l = __INST(readLimit); |
|
252 | 332 |
|
611 | 333 |
if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
1 | 334 |
|
1133 | 335 |
pos = __intVal(p); |
336 |
if (pos <= __intVal(l) && pos > 0) { |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
337 |
cls = __qClass(coll); |
1133 | 338 |
if (cls == @global(String)) { |
339 |
if (pos <= __stringSize(coll)) { |
|
340 |
ch = __stringVal(coll)[pos-1]; |
|
341 |
RETURN ( __MKCHARACTER(ch) ); |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
342 |
} |
1133 | 343 |
} else if (cls == @global(ByteArray)) { |
344 |
if (pos <= __byteArraySize(coll)) { |
|
345 |
ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
|
346 |
RETURN ( __MKSMALLINT(ch) ); |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
347 |
} |
1133 | 348 |
} else if (cls == @global(Array)) { |
349 |
if (pos <= __arraySize(coll)) { |
|
350 |
RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]); |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
351 |
} |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
352 |
} |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
353 |
} |
1 | 354 |
} |
355 |
%} |
|
356 |
. |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
357 |
(position > readLimit) ifTrue:[^ self pastEnd]. |
611 | 358 |
^ collection at:position |
1 | 359 |
! |
360 |
||
361 |
skipSeparators |
|
362 |
"skip all whitespace; next will return next non-white-space element. |
|
59 | 363 |
Return the peeked character or nil, if the end-of-stream was reached. |
2 | 364 |
- reimplemented for speed on String-Streams for faster scanning" |
1 | 365 |
|
366 |
%{ /* NOCONTEXT */ |
|
252 | 367 |
OBJ coll, p, l; |
1 | 368 |
|
1133 | 369 |
coll = __INST(collection); |
370 |
p = __INST(position); |
|
371 |
l = __INST(readLimit); |
|
252 | 372 |
|
373 |
if (__isString(coll) && __bothSmallInteger(p, l)) { |
|
202 | 374 |
REGISTER unsigned char *chars; |
375 |
REGISTER unsigned ch; |
|
376 |
REGISTER int pos; |
|
377 |
int limit; |
|
1 | 378 |
|
1133 | 379 |
pos = __intVal(p); |
202 | 380 |
if (pos <= 0) { |
381 |
RETURN ( nil ); |
|
382 |
} |
|
1 | 383 |
|
1133 | 384 |
limit = __intVal(l); |
329 | 385 |
if (limit > (__qSize(coll) - OHDR_SIZE)) |
386 |
limit = __qSize(coll) - OHDR_SIZE; |
|
1 | 387 |
|
1133 | 388 |
chars = (unsigned char *)(__stringVal(coll) + pos - 1); |
202 | 389 |
while (pos <= limit) { |
390 |
ch = *chars++; |
|
391 |
if ((ch != ' ') && (ch != '\t') && (ch != '\r') |
|
392 |
&& (ch != '\n') && (ch != 0x0B)) { |
|
1133 | 393 |
__INST(position) = __MKSMALLINT(pos); |
394 |
RETURN ( __MKCHARACTER(ch) ); |
|
202 | 395 |
} |
396 |
pos++; |
|
397 |
} |
|
1133 | 398 |
__INST(position) = __MKSMALLINT(pos); |
202 | 399 |
RETURN ( nil ); |
1 | 400 |
} |
401 |
%} |
|
402 |
. |
|
403 |
^ super skipSeparators |
|
404 |
! |
|
405 |
||
13 | 406 |
skipSeparatorsExceptCR |
407 |
"skip all whitespace except newlines; |
|
202 | 408 |
next will return next non-white-space element. |
409 |
- reimplemented for speed on String-Streams for faster scanning" |
|
410 |
||
13 | 411 |
%{ /* NOCONTEXT */ |
412 |
||
252 | 413 |
OBJ coll, p, l; |
414 |
||
1133 | 415 |
coll = __INST(collection); |
416 |
p = __INST(position); |
|
417 |
l = __INST(readLimit); |
|
252 | 418 |
|
419 |
if (__isString(coll) && __bothSmallInteger(p, l)) { |
|
202 | 420 |
REGISTER unsigned char *chars; |
421 |
REGISTER unsigned ch; |
|
422 |
REGISTER int pos; |
|
423 |
int limit; |
|
13 | 424 |
|
1133 | 425 |
pos = __intVal(p); |
202 | 426 |
if (pos <= 0) { |
427 |
RETURN ( nil ); |
|
428 |
} |
|
13 | 429 |
|
1133 | 430 |
limit = __intVal(l); |
329 | 431 |
if (limit > (__qSize(coll) - OHDR_SIZE)) |
432 |
limit = __qSize(coll) - OHDR_SIZE; |
|
13 | 433 |
|
1133 | 434 |
chars = (unsigned char *)(__stringVal(coll) + pos - 1); |
202 | 435 |
while (pos <= limit) { |
436 |
ch = *chars++; |
|
437 |
if ((ch != ' ') && (ch != '\t') && (ch != '\r') && (ch != 0x0B)) { |
|
1133 | 438 |
__INST(position) = __MKSMALLINT(pos); |
439 |
RETURN ( __MKCHARACTER(ch) ); |
|
202 | 440 |
} |
441 |
pos++; |
|
442 |
} |
|
1133 | 443 |
__INST(position) = __MKSMALLINT(pos); |
202 | 444 |
RETURN ( nil ); |
13 | 445 |
} |
446 |
%} |
|
447 |
. |
|
448 |
^ super skipSeparatorsExceptCR |
|
449 |
! |
|
450 |
||
611 | 451 |
skipThrough:anObject |
452 |
"skip all objects up-to and including anObject, return anObject on success, |
|
453 |
nil if end-of-stream is reached before. |
|
454 |
On success, the next read operation will return the element after anObject. |
|
455 |
- reimplemented for speed on String-Streams for faster scanning" |
|
456 |
||
457 |
%{ /* NOCONTEXT */ |
|
458 |
OBJ coll, p, l; |
|
459 |
||
1133 | 460 |
coll = __INST(collection); |
461 |
p = __INST(position); |
|
462 |
l = __INST(readLimit); |
|
611 | 463 |
|
464 |
if (__isString(coll) |
|
465 |
&& __isCharacter(anObject) |
|
466 |
&& __bothSmallInteger(p, l)) { |
|
467 |
REGISTER unsigned char *chars; |
|
468 |
REGISTER int pos, limit; |
|
469 |
unsigned ch; |
|
470 |
int sz; |
|
471 |
||
1133 | 472 |
pos = __intVal(p); |
611 | 473 |
if (pos <= 0) { |
474 |
RETURN ( nil ); |
|
475 |
} |
|
476 |
||
1133 | 477 |
limit = __intVal(l); |
478 |
sz = __stringSize(coll); |
|
611 | 479 |
if (limit > sz) limit = sz; |
480 |
||
1133 | 481 |
chars = (unsigned char *)(__stringVal(coll) + pos - 1); |
482 |
ch = __intVal(_characterVal(anObject)) & 0xFF; |
|
611 | 483 |
while (pos < limit) { |
484 |
if (*chars == ch) { |
|
485 |
ch = *++chars; |
|
486 |
pos++; |
|
1133 | 487 |
__INST(position) = __MKSMALLINT(pos); |
611 | 488 |
RETURN ( anObject ); |
489 |
} |
|
490 |
chars++; |
|
491 |
pos++; |
|
492 |
} |
|
493 |
RETURN ( nil ); |
|
494 |
} |
|
495 |
%} |
|
496 |
. |
|
497 |
^ super skipThrough:anObject |
|
498 |
! |
|
499 |
||
1 | 500 |
skipToAll:aCollection |
501 |
"skip for the sequence given by the argument, aCollection; |
|
502 |
return nil if not found, self otherwise. On a successful match, next read |
|
503 |
will return elements of aCollection." |
|
504 |
||
505 |
|oldPos buffer l first idx| |
|
506 |
||
507 |
oldPos := self position. |
|
508 |
l := aCollection size. |
|
509 |
first := aCollection at:1. |
|
510 |
[self atEnd] whileFalse:[ |
|
202 | 511 |
buffer := self next:l. |
512 |
buffer = aCollection ifTrue:[ |
|
513 |
self position:(self position - l). |
|
514 |
^ self |
|
515 |
]. |
|
516 |
idx := buffer indexOf:first startingAt:2. |
|
517 |
idx == 0 ifFalse:[ |
|
518 |
self position:(self position - l + idx - 1) |
|
519 |
] |
|
1 | 520 |
]. |
521 |
self position:oldPos. |
|
522 |
^ nil |
|
523 |
||
59 | 524 |
" |
525 |
|s| |
|
1 | 526 |
s := ReadStream on:'12345678901234567890'. |
527 |
s skipToAll:'901'. |
|
59 | 528 |
s next:4 |
529 |
" |
|
1 | 530 |
! ! |
531 |
||
59 | 532 |
!ReadStream methodsFor:'writing'! |
1 | 533 |
|
534 |
nextPut:anElement |
|
10 | 535 |
"catch write access to readstreams - report an error" |
536 |
||
537 |
self shouldNotImplement |
|
1 | 538 |
! ! |
611 | 539 |
|
701 | 540 |
!ReadStream class methodsFor:'documentation'! |
541 |
||
542 |
version |
|
1138
993e6ffdbf51
removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
543 |
^ '$Header: /cvs/stx/stx/libbasic/ReadStream.st,v 1.25 1996-04-06 13:22:37 cg Exp $' |
701 | 544 |
! ! |