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