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