author | Claus Gittinger <cg@exept.de> |
Mon, 03 Jun 2013 20:39:38 +0200 | |
changeset 15356 | 854a02a2bebc |
parent 15351 | be2b7a7ca2ca |
child 15582 | 11a8428d9a10 |
child 18066 | 89d51443ba6f |
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 |
||
5310 | 127 |
copyFrom:beginning to:end |
128 |
^ collection copyFrom:beginning to:end |
|
129 |
! |
|
130 |
||
345 | 131 |
isReadable |
2997 | 132 |
"return true, if reading is supported by the recevier. |
133 |
Here, true is always returned." |
|
134 |
||
345 | 135 |
^ true |
2997 | 136 |
|
137 |
"Modified: 4.10.1997 / 17:59:21 / cg" |
|
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
138 |
! |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
139 |
|
6315 | 140 |
isWritable |
141 |
"return true, if writing is supported by the recevier. |
|
142 |
This has to be redefined in concrete subclasses." |
|
143 |
||
144 |
^ false |
|
145 |
! |
|
146 |
||
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
147 |
size |
14936 | 148 |
"return the number of remaining elements in the streamed collection." |
2997 | 149 |
|
14936 | 150 |
^ collection size - position |
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 |
4826
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
314 |
"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
|
315 |
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
|
316 |
- tuned for a bit more speed on String/ByteArray/Array-Streams" |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
317 |
|
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
318 |
|ret| |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
319 |
|
4826
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
320 |
%{ /* NOCONTEXT */ |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
321 |
|
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
322 |
REGISTER int pos; |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
323 |
unsigned ch; |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
324 |
OBJ coll, p, l; |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
325 |
|
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
326 |
coll = __INST(collection); |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
327 |
p = __INST(position); |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
328 |
l = __INST(readLimit); |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
329 |
|
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
330 |
if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
331 |
|
15351 | 332 |
pos = __intVal(p); |
333 |
/* make 1-based */ |
|
334 |
pos = pos + 1; |
|
335 |
if (pos > 0 && pos <= __intVal(l)) { |
|
336 |
OBJ cls, ret; |
|
4826
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
337 |
|
15351 | 338 |
cls = __qClass(coll); |
339 |
if (cls == @global(String)) { |
|
340 |
if (pos <= __stringSize(coll)) { |
|
341 |
ch = __stringVal(coll)[pos-1]; |
|
342 |
ret = __mkSmallInteger(ch); |
|
343 |
__INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
|
344 |
RETURN ( ret ); |
|
345 |
} |
|
346 |
} else if (cls == @global(ByteArray)) { |
|
347 |
if (pos <= __byteArraySize(coll)) { |
|
348 |
ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
|
349 |
ret = __mkSmallInteger(ch); |
|
350 |
__INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
|
351 |
RETURN ( ret ); |
|
352 |
} |
|
353 |
} else if (cls == @global(Array)) { |
|
354 |
if (pos <= __arraySize(coll)) { |
|
355 |
ret = __ArrayInstPtr(coll)->a_element[pos-1]; |
|
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 |
} |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
362 |
%}. |
15356 | 363 |
(position >= readLimit) ifTrue:[^ self pastEndRead]. |
15351 | 364 |
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
|
365 |
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
|
366 |
^ ret asInteger |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
367 |
! |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
368 |
|
8530
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
369 |
nextBytes:numBytes into:aCollection startingAt:initialIndex |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
370 |
"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
|
371 |
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
|
372 |
collection. |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
373 |
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
|
374 |
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
|
375 |
|
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
376 |
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
|
377 |
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
|
378 |
streams." |
8530
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
379 |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
380 |
((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
|
381 |
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
|
382 |
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
|
383 |
and:[aCollection isByteCollection |
9458
ea81e322a954
off-by-one error in #nextBytes:into:startingAt:
Stefan Vogel <sv@exept.de>
parents:
9457
diff
changeset
|
384 |
]]]) ifTrue:[ |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
385 |
"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
|
386 |
aCollection |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
387 |
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
|
388 |
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
|
389 |
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
|
390 |
^ numBytes |
8530
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
391 |
]. |
9458
ea81e322a954
off-by-one error in #nextBytes:into:startingAt:
Stefan Vogel <sv@exept.de>
parents:
9457
diff
changeset
|
392 |
"do it the hard way" |
8530
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
393 |
^ 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
|
394 |
|
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
395 |
" |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
396 |
|s n buffer| |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
397 |
|
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
398 |
buffer := ByteArray new:10. |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
399 |
|
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
400 |
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
|
401 |
s next:3. |
edcadeea17a1
tuned reading long strings & byteArrays from byteArray streams.
Claus Gittinger <cg@exept.de>
parents:
8140
diff
changeset
|
402 |
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
|
403 |
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
|
404 |
" |
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 |
|
611 | 407 |
nextDecimalInteger |
408 |
"read the next integer in radix 10. dont skip whitespace. |
|
409 |
- tuned for speed on String-Streams for faster scanning" |
|
410 |
||
411 |
|value nextOne| |
|
412 |
%{ |
|
413 |
int pos, limit, sz; |
|
414 |
REGISTER unsigned char *cp; |
|
415 |
REGISTER unsigned ch; |
|
8914 | 416 |
INT val = 0; |
611 | 417 |
OBJ coll, p, l; |
418 |
||
1133 | 419 |
coll = __INST(collection); |
420 |
p = __INST(position); |
|
421 |
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
|
422 |
|
12479
62b11c1f462e
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12176
diff
changeset
|
423 |
if (__isStringLike(coll) && __bothSmallInteger(p, l)) { |
611 | 424 |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
425 |
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
|
426 |
/* 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
|
427 |
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
|
428 |
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
|
429 |
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
|
430 |
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
|
431 |
limit = sz; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
432 |
cp = __stringVal(coll) + pos - 1; |
611 | 433 |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
434 |
for (;;) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
435 |
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
|
436 |
ch = *cp; |
611 | 437 |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
438 |
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
|
439 |
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
|
440 |
pos++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
441 |
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
|
442 |
cp++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
443 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
444 |
/* 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
|
445 |
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
|
446 |
__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
|
447 |
RETURN (__mkSmallInteger(val)); |
611 | 448 |
} |
449 |
oops: |
|
8913 | 450 |
value = __mkSmallInteger(val); |
611 | 451 |
%} |
452 |
. |
|
453 |
"fall-back for non-string streams - we have to continue where |
|
454 |
above primitive left off, in case of a large integer ... |
|
455 |
(instead of doing a super nextDecimalInteger)" |
|
456 |
||
457 |
nextOne := self peek. |
|
458 |
[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
|
459 |
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
|
460 |
nextOne := self nextPeek |
611 | 461 |
]. |
462 |
^ value |
|
463 |
! |
|
464 |
||
9457 | 465 |
nextOrNil |
466 |
"return the next element; advance read pointer. |
|
467 |
return nil, if there is no next element. |
|
468 |
- tuned for a bit more speed on String/ByteArray/Array-Streams" |
|
469 |
||
470 |
|ret| |
|
471 |
||
472 |
%{ /* NOCONTEXT */ |
|
473 |
||
474 |
REGISTER int pos; |
|
475 |
unsigned ch; |
|
476 |
OBJ coll, p, l; |
|
477 |
||
478 |
coll = __INST(collection); |
|
479 |
p = __INST(position); |
|
480 |
l = __INST(readLimit); |
|
481 |
||
482 |
if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
|
15351 | 483 |
pos = __intVal(p); |
484 |
/* make 1-based */ |
|
485 |
pos = pos + 1; |
|
486 |
if (pos > 0) { |
|
487 |
OBJ cls, ret; |
|
9457 | 488 |
|
15351 | 489 |
if (pos > __intVal(l)) { |
490 |
RETURN(nil); |
|
491 |
} |
|
9457 | 492 |
|
15351 | 493 |
cls = __qClass(coll); |
494 |
if (cls == @global(String)) { |
|
495 |
if (pos <= __stringSize(coll)) { |
|
496 |
ch = __stringVal(coll)[pos-1]; |
|
497 |
ret = __MKCHARACTER(ch); |
|
498 |
__INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
|
499 |
RETURN ( ret ); |
|
500 |
} |
|
501 |
} else if (cls == @global(ByteArray)) { |
|
502 |
if (pos <= __byteArraySize(coll)) { |
|
503 |
ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
|
504 |
ret = __mkSmallInteger(ch); |
|
505 |
__INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
|
506 |
RETURN ( ret ); |
|
507 |
} |
|
508 |
} else if (cls == @global(Unicode16String)) { |
|
509 |
if (pos <= __unicode16StringSize(coll)) { |
|
510 |
ch = __Unicode16StringInstPtr(coll)->s_element[pos-1]; |
|
511 |
ret = __MKUCHARACTER(ch); |
|
512 |
__INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
|
513 |
RETURN ( ret ); |
|
514 |
} |
|
515 |
} else if (cls == @global(Array)) { |
|
516 |
if (pos <= __arraySize(coll)) { |
|
517 |
ret = __ArrayInstPtr(coll)->a_element[pos-1]; |
|
518 |
__INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
|
519 |
RETURN ( ret ); |
|
520 |
} |
|
521 |
} |
|
522 |
} |
|
9457 | 523 |
} |
524 |
%}. |
|
15351 | 525 |
ret := collection at:(position + 1). |
9457 | 526 |
position := position + 1. |
527 |
^ ret |
|
528 |
! |
|
529 |
||
611 | 530 |
nextPeek |
531 |
"advance read pointer return the peek element. |
|
532 |
this is equivalent to (self next; peek). |
|
533 |
- tuned for speed on String-Streams for faster scanning" |
|
534 |
||
535 |
%{ /* NOCONTEXT */ |
|
536 |
OBJ coll, l, p; |
|
537 |
||
1133 | 538 |
coll = __INST(collection); |
539 |
p = __INST(position); |
|
540 |
l = __INST(readLimit); |
|
611 | 541 |
|
12479
62b11c1f462e
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12176
diff
changeset
|
542 |
if (__isStringLike(coll) && __bothSmallInteger(p, l)) { |
15351 | 543 |
REGISTER int pos; |
544 |
unsigned ch; |
|
611 | 545 |
|
15351 | 546 |
pos = __intVal(p); |
547 |
/* make 1-based */ |
|
548 |
pos = pos + 1; |
|
549 |
if ((pos > 0) && (pos < __intVal(l)) && (pos < __stringSize(coll))) { |
|
550 |
pos = pos + 1; |
|
551 |
ch = __stringVal(coll)[pos-1]; |
|
552 |
/* make ZeroPosition-based */ |
|
553 |
pos = pos - 1; |
|
554 |
__INST(position) = __mkSmallInteger(pos); |
|
555 |
RETURN ( __MKCHARACTER(ch) ); |
|
556 |
} |
|
611 | 557 |
} |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
558 |
%}. |
15356 | 559 |
(position >= readLimit) ifTrue:[^ self pastEndRead]. |
611 | 560 |
position := position + 1. |
15356 | 561 |
(position >= readLimit) ifTrue:[^ self pastEndRead]. |
15351 | 562 |
^ collection at:(position + 1) |
611 | 563 |
! |
564 |
||
565 |
peek |
|
566 |
"return the next element; do NOT advance read pointer. |
|
567 |
return nil, if there is no next element. |
|
568 |
- tuned for a bit more speed on String/ByteArray/Array-Streams" |
|
1 | 569 |
|
570 |
%{ /* NOCONTEXT */ |
|
611 | 571 |
|
572 |
REGISTER int pos; |
|
573 |
unsigned ch; |
|
574 |
OBJ coll; |
|
575 |
OBJ cls, p, l; |
|
1 | 576 |
|
1133 | 577 |
coll = __INST(collection); |
578 |
p = __INST(position); |
|
579 |
l = __INST(readLimit); |
|
252 | 580 |
|
611 | 581 |
if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
1 | 582 |
|
15351 | 583 |
pos = __intVal(p); |
584 |
/* make 1-based */ |
|
585 |
pos = pos + 1; |
|
586 |
if (pos <= __intVal(l) && pos > 0) { |
|
587 |
cls = __qClass(coll); |
|
588 |
if (cls == @global(String)) { |
|
589 |
if (pos <= __stringSize(coll)) { |
|
590 |
ch = __stringVal(coll)[pos-1]; |
|
591 |
RETURN ( __MKCHARACTER(ch) ); |
|
592 |
} |
|
593 |
} else if (cls == @global(ByteArray)) { |
|
594 |
if (pos <= __byteArraySize(coll)) { |
|
595 |
ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
|
596 |
RETURN ( __mkSmallInteger(ch) ); |
|
597 |
} |
|
598 |
} else if (cls == @global(Array)) { |
|
599 |
if (pos <= __arraySize(coll)) { |
|
600 |
RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]); |
|
601 |
} |
|
602 |
} |
|
603 |
} |
|
1 | 604 |
} |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
605 |
%}. |
15356 | 606 |
(position >= readLimit) ifTrue:[^ self pastEndRead]. |
15351 | 607 |
^ collection at:(position + 1) |
1 | 608 |
! |
609 |
||
3316 | 610 |
peekOrNil |
611 |
"return the next element; do NOT advance read pointer. |
|
612 |
return nil, if there is no next element. |
|
613 |
This is much like #peek - |
|
614 |
However, unlike #peek, this does not raise an atEnd-query signal - even |
|
615 |
if handled. Instead, nil is returned immediately." |
|
616 |
||
617 |
%{ /* NOCONTEXT */ |
|
618 |
||
619 |
REGISTER int pos; |
|
620 |
unsigned ch; |
|
621 |
OBJ coll; |
|
622 |
OBJ cls, p, l; |
|
623 |
||
624 |
coll = __INST(collection); |
|
625 |
p = __INST(position); |
|
626 |
l = __INST(readLimit); |
|
627 |
||
628 |
if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
|
629 |
||
15351 | 630 |
pos = __intVal(p); |
631 |
/* make 1-based */ |
|
632 |
pos = pos + 1; |
|
633 |
if (pos <= __intVal(l) && pos > 0) { |
|
634 |
cls = __qClass(coll); |
|
635 |
if (cls == @global(String)) { |
|
636 |
if (pos <= __stringSize(coll)) { |
|
637 |
ch = __stringVal(coll)[pos-1]; |
|
638 |
RETURN ( __MKCHARACTER(ch) ); |
|
639 |
} |
|
640 |
RETURN ( nil ); |
|
641 |
} else if (cls == @global(ByteArray)) { |
|
642 |
if (pos <= __byteArraySize(coll)) { |
|
643 |
ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
|
644 |
RETURN ( __mkSmallInteger(ch) ); |
|
645 |
} |
|
646 |
RETURN ( nil ); |
|
647 |
} else if (cls == @global(Array)) { |
|
648 |
if (pos <= __arraySize(coll)) { |
|
649 |
RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]); |
|
650 |
} |
|
651 |
RETURN ( nil ); |
|
652 |
} |
|
653 |
} |
|
3316 | 654 |
} |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
655 |
%}. |
15356 | 656 |
(position >= readLimit) ifTrue:[^ nil]. |
15351 | 657 |
^ collection at:(position + 1) |
3316 | 658 |
! |
659 |
||
1 | 660 |
skipSeparators |
661 |
"skip all whitespace; next will return next non-white-space element. |
|
59 | 662 |
Return the peeked character or nil, if the end-of-stream was reached. |
2 | 663 |
- reimplemented for speed on String-Streams for faster scanning" |
1 | 664 |
|
665 |
%{ /* NOCONTEXT */ |
|
252 | 666 |
OBJ coll, p, l; |
1 | 667 |
|
1133 | 668 |
coll = __INST(collection); |
669 |
p = __INST(position); |
|
670 |
l = __INST(readLimit); |
|
252 | 671 |
|
12479
62b11c1f462e
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12176
diff
changeset
|
672 |
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
|
673 |
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
|
674 |
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
|
675 |
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
|
676 |
int limit; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
677 |
int sz; |
1 | 678 |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
679 |
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
|
680 |
/* 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
|
681 |
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
|
682 |
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
|
683 |
RETURN ( nil ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
684 |
} |
1 | 685 |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
686 |
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
|
687 |
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
|
688 |
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
|
689 |
limit = sz; |
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 |
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
|
693 |
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
|
694 |
pos++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
695 |
ch = *chars++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
696 |
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
|
697 |
|| ((ch != ' ') |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
698 |
&& (ch != '\t') |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
699 |
&& (ch != '\r') |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
700 |
&& (ch != '\n') |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
701 |
&& (ch != '\f') |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
702 |
&& (ch != 0x0B))) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
703 |
/* 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
|
704 |
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
|
705 |
__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
|
706 |
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
|
707 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
708 |
} |
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); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
712 |
RETURN ( nil ); |
1 | 713 |
} |
1406 | 714 |
%}. |
1 | 715 |
^ super skipSeparators |
1406 | 716 |
|
717 |
" |
|
718 |
|s| |
|
719 |
||
720 |
s := ' hello world ' readStream. |
|
721 |
s skipSeparators. |
|
722 |
s next. |
|
723 |
" |
|
1 | 724 |
! |
725 |
||
13 | 726 |
skipSeparatorsExceptCR |
727 |
"skip all whitespace except newlines; |
|
202 | 728 |
next will return next non-white-space element. |
729 |
- reimplemented for speed on String-Streams for faster scanning" |
|
730 |
||
13 | 731 |
%{ /* NOCONTEXT */ |
732 |
||
252 | 733 |
OBJ coll, p, l; |
734 |
||
1133 | 735 |
coll = __INST(collection); |
736 |
p = __INST(position); |
|
737 |
l = __INST(readLimit); |
|
252 | 738 |
|
12479
62b11c1f462e
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12176
diff
changeset
|
739 |
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
|
740 |
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
|
741 |
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
|
742 |
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
|
743 |
int limit; |
13 | 744 |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
745 |
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
|
746 |
/* 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
|
747 |
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
|
748 |
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
|
749 |
RETURN ( nil ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
750 |
} |
2162
7e1601f633b6
ff is a separator too (in #skipSeparators*)
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
751 |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
752 |
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
|
753 |
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
|
754 |
limit = __qSize(coll) - OHDR_SIZE; |
13 | 755 |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
756 |
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
|
757 |
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
|
758 |
ch = *chars++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
759 |
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
|
760 |
|| ( |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
761 |
(ch != ' ') |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
762 |
&& (ch != '\t') |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
763 |
&& (ch != '\f') |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
764 |
&& (ch != '\b') |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
765 |
&& (ch != 0x0B))) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
766 |
/* 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
|
767 |
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
|
768 |
__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
|
769 |
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
|
770 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
771 |
pos++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
772 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
773 |
/* make ZeroPosition-based */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
774 |
pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
775 |
__INST(position) = __mkSmallInteger(pos); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
776 |
RETURN ( nil ); |
13 | 777 |
} |
778 |
%} |
|
779 |
. |
|
780 |
^ super skipSeparatorsExceptCR |
|
781 |
! |
|
782 |
||
611 | 783 |
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
|
784 |
"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
|
785 |
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
|
786 |
otherwise (i.e. if not found) return nil and leave the stream positioned at the end. |
611 | 787 |
On success, the next read operation will return the element after anObject. |
788 |
- reimplemented for speed on String-Streams for faster scanning" |
|
789 |
||
790 |
%{ /* NOCONTEXT */ |
|
791 |
OBJ coll, p, l; |
|
792 |
||
1133 | 793 |
coll = __INST(collection); |
794 |
p = __INST(position); |
|
795 |
l = __INST(readLimit); |
|
611 | 796 |
|
12479
62b11c1f462e
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12176
diff
changeset
|
797 |
if (__isStringLike(coll) |
611 | 798 |
&& __isCharacter(anObject) |
799 |
&& __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
|
800 |
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
|
801 |
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
|
802 |
unsigned ch; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
803 |
int sz; |
611 | 804 |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
805 |
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
|
806 |
/* 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
|
807 |
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
|
808 |
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
|
809 |
RETURN ( nil ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
810 |
} |
611 | 811 |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
812 |
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
|
813 |
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
|
814 |
if (limit > sz) limit = sz; |
611 | 815 |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
816 |
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
|
817 |
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
|
818 |
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
|
819 |
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
|
820 |
ch = *++chars; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
821 |
pos++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
822 |
/* 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
|
823 |
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
|
824 |
__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
|
825 |
RETURN ( self ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
826 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
827 |
chars++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
828 |
pos++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
829 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
14936
diff
changeset
|
830 |
/* 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
|
831 |
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
|
832 |
__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
|
833 |
RETURN ( nil ); |
611 | 834 |
} |
6011
3b91d7834ca5
fixed: skipThrough dod not position atEnd if the element was not found.
Claus Gittinger <cg@exept.de>
parents:
5810
diff
changeset
|
835 |
%}. |
611 | 836 |
^ super skipThrough:anObject |
1 | 837 |
! ! |
838 |
||
59 | 839 |
!ReadStream methodsFor:'writing'! |
1 | 840 |
|
841 |
nextPut:anElement |
|
10 | 842 |
"catch write access to readstreams - report an error" |
843 |
||
844 |
self shouldNotImplement |
|
1 | 845 |
! ! |
611 | 846 |
|
2162
7e1601f633b6
ff is a separator too (in #skipSeparators*)
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
847 |
!ReadStream class methodsFor:'documentation'! |
701 | 848 |
|
849 |
version |
|
15356 | 850 |
^ '$Header: /cvs/stx/stx/libbasic/ReadStream.st,v 1.69 2013-06-03 18:39:38 cg Exp $' |
12176 | 851 |
! |
852 |
||
853 |
version_CVS |
|
15356 | 854 |
^ '$Header: /cvs/stx/stx/libbasic/ReadStream.st,v 1.69 2013-06-03 18:39:38 cg Exp $' |
701 | 855 |
! ! |
14936 | 856 |