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