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