author | Claus Gittinger <cg@exept.de> |
Mon, 31 Mar 2003 11:53:22 +0200 | |
changeset 7142 | 7a6297c86ef4 |
parent 7114 | acc13967229e |
child 7483 | 471b86450ede |
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 |
" |
|
12 |
||
5810 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
1 | 15 |
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
|
16 |
instanceVariableNames:'' |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
17 |
classVariableNames:'' |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
18 |
poolDictionaries:'' |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
19 |
category:'Streams' |
1 | 20 |
! |
21 |
||
2162
7e1601f633b6
ff is a separator too (in #skipSeparators*)
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
22 |
!ReadStream class methodsFor:'documentation'! |
88 | 23 |
|
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
202 | 27 |
All Rights Reserved |
1 | 28 |
|
88 | 29 |
This software is furnished under a license and may be used |
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
1 | 37 |
|
88 | 38 |
documentation |
39 |
" |
|
40 |
ReadStream defines protocol for reading streamwise over collections. |
|
1295 | 41 |
|
42 |
[author:] |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
43 |
Claus Gittinger |
1295 | 44 |
|
88 | 45 |
" |
46 |
! ! |
|
1 | 47 |
|
202 | 48 |
!ReadStream methodsFor:'converting'! |
49 |
||
50 |
readStream |
|
51 |
"return a readStream from the receiver. Since this is already |
|
52 |
a readStream, return self." |
|
53 |
||
54 |
^ self |
|
55 |
! ! |
|
56 |
||
1400 | 57 |
!ReadStream methodsFor:'emphasis'! |
58 |
||
59 |
emphasis |
|
60 |
"return the emphasis of the current (i.e. next returned by #next) |
|
61 |
element. Streams on a string will return nil for all elements. |
|
62 |
Streams on collections which nothing at all about emphasises, |
|
63 |
will report an error." |
|
64 |
||
7114 | 65 |
^ collection emphasisAt:(position - ZeroPosition + 1). |
1400 | 66 |
|
67 |
" |
|
68 |
|t s| |
|
69 |
||
70 |
t := 'hello world' asText |
|
7114 | 71 |
emphasizeFrom:1 to:5 with:#bold; |
72 |
emphasizeFrom:7 to:11 with:#italic. |
|
1400 | 73 |
|
74 |
s := t readStream. |
|
75 |
[s atEnd] whileFalse:[ |
|
7114 | 76 |
Transcript show:(s emphasis); show:' '. |
77 |
Transcript show:''''; show:(s next); showCR:''''. |
|
1400 | 78 |
]. |
79 |
" |
|
80 |
||
81 |
"Modified: 15.5.1996 / 17:30:33 / cg" |
|
82 |
! ! |
|
83 |
||
6814 | 84 |
!ReadStream methodsFor:'misc'! |
85 |
||
86 |
readWait |
|
87 |
^ self "/ never have to wait |
|
88 |
! |
|
89 |
||
90 |
readWaitWithTimeoutMs:millis |
|
91 |
^ false "/ never have to wait |
|
92 |
! ! |
|
93 |
||
345 | 94 |
!ReadStream methodsFor:'queries'! |
95 |
||
5310 | 96 |
copyFrom:beginning to:end |
97 |
^ collection copyFrom:beginning to:end |
|
98 |
! |
|
99 |
||
345 | 100 |
isReadable |
2997 | 101 |
"return true, if reading is supported by the recevier. |
102 |
Here, true is always returned." |
|
103 |
||
345 | 104 |
^ true |
2997 | 105 |
|
106 |
"Modified: 4.10.1997 / 17:59:21 / cg" |
|
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
107 |
! |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
108 |
|
6315 | 109 |
isWritable |
110 |
"return true, if writing is supported by the recevier. |
|
111 |
This has to be redefined in concrete subclasses." |
|
112 |
||
113 |
^ false |
|
114 |
! |
|
115 |
||
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
116 |
size |
2997 | 117 |
"return the number of elements in the streamed collection." |
118 |
||
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
119 |
^ collection size |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
120 |
|
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
121 |
"Created: 13.9.1996 / 18:14:35 / cg" |
2997 | 122 |
"Modified: 4.10.1997 / 17:59:45 / cg" |
345 | 123 |
! ! |
124 |
||
59 | 125 |
!ReadStream methodsFor:'reading'! |
1 | 126 |
|
127 |
next |
|
128 |
"return the next element; advance read pointer. |
|
2 | 129 |
return nil, if there is no next element. |
345 | 130 |
- tuned for a bit more speed on String/ByteArray/Array-Streams" |
1 | 131 |
|
132 |
|ret| |
|
133 |
||
134 |
%{ /* NOCONTEXT */ |
|
135 |
||
136 |
REGISTER int pos; |
|
137 |
unsigned ch; |
|
252 | 138 |
OBJ coll, p, l; |
1 | 139 |
|
1133 | 140 |
coll = __INST(collection); |
141 |
p = __INST(position); |
|
142 |
l = __INST(readLimit); |
|
1 | 143 |
|
252 | 144 |
if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
145 |
||
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
146 |
pos = __intVal(p); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
147 |
/* make 1-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
148 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
149 |
if (pos > 0 && pos <= __intVal(l)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
150 |
OBJ cls; |
59 | 151 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
152 |
cls = __qClass(coll); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
153 |
if (cls == @global(String)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
154 |
if (pos <= __stringSize(coll)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
155 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
156 |
ch = __stringVal(coll)[pos-1]; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
157 |
RETURN ( __MKCHARACTER(ch) ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
158 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
159 |
} else if (cls == @global(ByteArray)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
160 |
if (pos <= __byteArraySize(coll)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
161 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
162 |
ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
163 |
RETURN ( __MKSMALLINT(ch) ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
164 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
165 |
} else if (cls == @global(Array)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
166 |
if (pos <= __arraySize(coll)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
167 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
168 |
RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
169 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
170 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
171 |
} |
1 | 172 |
} |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
173 |
%}. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
174 |
((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEnd]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
175 |
ret := collection at:(position + 1 - ZeroPosition). |
1 | 176 |
position := position + 1. |
177 |
^ ret |
|
178 |
! |
|
179 |
||
252 | 180 |
nextAlphaNumericWord |
1 | 181 |
"read the next word (i.e. up to non letter-or-digit). |
182 |
return a string containing those characters. |
|
3112
ccf7121ddae8
nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents:
2997
diff
changeset
|
183 |
Skips any non-alphanumeric chars first. |
59 | 184 |
- tuned for speed on String-Streams for faster scanning" |
1 | 185 |
%{ |
186 |
/* speedup, if collection is a string */ |
|
187 |
||
188 |
int pos, limit, sz; |
|
189 |
int len; |
|
13 | 190 |
char buffer[256]; |
191 |
REGISTER unsigned char *cp; |
|
192 |
REGISTER unsigned ch; |
|
252 | 193 |
OBJ coll, p, l; |
1 | 194 |
|
1133 | 195 |
coll = __INST(collection); |
196 |
p = __INST(position); |
|
197 |
l = __INST(readLimit); |
|
252 | 198 |
|
199 |
if (__isString(coll) && __bothSmallInteger(p, l)) { |
|
200 |
||
1133 | 201 |
pos = __intVal(p); |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
202 |
/* make 1-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
203 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
204 |
|
1133 | 205 |
limit = __intVal(l); |
329 | 206 |
sz = __qSize(coll) - OHDR_SIZE; |
202 | 207 |
if (sz < limit) |
208 |
limit = sz; |
|
1133 | 209 |
cp = __stringVal(coll) + pos - 1; |
1 | 210 |
|
202 | 211 |
for (;;) { |
212 |
if (pos > limit) break; |
|
213 |
ch = *cp; |
|
1 | 214 |
|
3112
ccf7121ddae8
nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents:
2997
diff
changeset
|
215 |
if (((ch >= 'a') && (ch <= 'z')) || |
ccf7121ddae8
nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents:
2997
diff
changeset
|
216 |
((ch >= 'A') && (ch <= 'Z')) || |
ccf7121ddae8
nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents:
2997
diff
changeset
|
217 |
((ch >= '0') && (ch <= '9'))) |
ccf7121ddae8
nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents:
2997
diff
changeset
|
218 |
break; |
202 | 219 |
cp++; |
220 |
pos++; |
|
221 |
} |
|
1 | 222 |
|
202 | 223 |
len = 0; |
224 |
for (;;) { |
|
225 |
if (pos > limit) break; |
|
226 |
ch = *cp & 0xFF; |
|
1 | 227 |
|
202 | 228 |
if (! (((ch >= 'a') && (ch <= 'z')) || |
229 |
((ch >= 'A') && (ch <= 'Z')) || |
|
230 |
((ch >= '0') && (ch <= '9')))) |
|
231 |
break; |
|
232 |
buffer[len++] = ch; |
|
233 |
if (len >= (sizeof(buffer)-1)) { |
|
234 |
/* emergency */ |
|
235 |
break; |
|
236 |
} |
|
237 |
pos++; |
|
238 |
cp++; |
|
239 |
} |
|
1 | 240 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
241 |
/* make ZeroPosition-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
242 |
pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
1133 | 243 |
__INST(position) = __MKSMALLINT(pos); |
202 | 244 |
buffer[len] = '\0'; |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1665
diff
changeset
|
245 |
RETURN ( (len != 0) ? __MKSTRING_L(buffer, len) : nil ); |
1 | 246 |
} |
247 |
%} |
|
248 |
. |
|
252 | 249 |
^ super nextAlphaNumericWord |
1 | 250 |
! |
251 |
||
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
252 |
nextByte |
4826
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
253 |
"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
|
254 |
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
|
255 |
- 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
|
256 |
|
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
257 |
|ret| |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
258 |
|
4826
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
259 |
%{ /* NOCONTEXT */ |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
260 |
|
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
261 |
REGISTER int pos; |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
262 |
unsigned ch; |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
263 |
OBJ coll, p, l; |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
264 |
|
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
265 |
coll = __INST(collection); |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
266 |
p = __INST(position); |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
267 |
l = __INST(readLimit); |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
268 |
|
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
269 |
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
|
270 |
|
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
271 |
pos = __intVal(p); |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
272 |
/* make 1-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
273 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
4826
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
274 |
if (pos > 0 && pos <= __intVal(l)) { |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
275 |
OBJ cls; |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
276 |
|
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
277 |
cls = __qClass(coll); |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
278 |
if (cls == @global(String)) { |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
279 |
if (pos <= __stringSize(coll)) { |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
280 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1); |
4826
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
281 |
ch = __stringVal(coll)[pos-1]; |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
282 |
RETURN ( __MKSMALLINT(ch) ); |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
283 |
} |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
284 |
} else if (cls == @global(ByteArray)) { |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
285 |
if (pos <= __byteArraySize(coll)) { |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
286 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1); |
4826
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
287 |
ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
288 |
RETURN ( __MKSMALLINT(ch) ); |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
289 |
} |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
290 |
} else if (cls == @global(Array)) { |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
291 |
if (pos <= __arraySize(coll)) { |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
292 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1); |
4826
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
293 |
RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]); |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
294 |
} |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
295 |
} |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
296 |
} |
ff30434f0feb
#nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
297 |
} |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
298 |
%}. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
299 |
((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEnd]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
300 |
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
|
301 |
position := position + 1. |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
302 |
^ ret |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
303 |
! |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
304 |
|
611 | 305 |
nextDecimalInteger |
306 |
"read the next integer in radix 10. dont skip whitespace. |
|
307 |
- tuned for speed on String-Streams for faster scanning" |
|
308 |
||
309 |
|value nextOne| |
|
310 |
%{ |
|
311 |
int pos, limit, sz; |
|
312 |
REGISTER unsigned char *cp; |
|
313 |
REGISTER unsigned ch; |
|
314 |
int val = 0; |
|
315 |
OBJ coll, p, l; |
|
316 |
||
1133 | 317 |
coll = __INST(collection); |
318 |
p = __INST(position); |
|
319 |
l = __INST(readLimit); |
|
611 | 320 |
|
321 |
if (__isString(coll) && __bothSmallInteger(p, l)) { |
|
322 |
||
1133 | 323 |
pos = __intVal(p); |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
324 |
/* make 1-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
325 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
1133 | 326 |
limit = __intVal(l); |
611 | 327 |
sz = __qSize(coll) - OHDR_SIZE; |
328 |
if (sz < limit) |
|
329 |
limit = sz; |
|
1133 | 330 |
cp = __stringVal(coll) + pos - 1; |
611 | 331 |
|
332 |
for (;;) { |
|
333 |
if (pos > limit) break; |
|
334 |
ch = *cp; |
|
335 |
||
336 |
if ((ch < '0') || (ch > '9')) break; |
|
337 |
val = val * 10 + (ch - '0'); |
|
338 |
pos++; |
|
339 |
if (val > (_MAX_INT / 10)) goto oops; |
|
340 |
cp++; |
|
341 |
} |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
342 |
/* make ZeroPosition-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
343 |
pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
1133 | 344 |
__INST(position) = __MKSMALLINT(pos); |
4271
d1878c9dc428
oops - return instead of RETURN macro
Claus Gittinger <cg@exept.de>
parents:
3316
diff
changeset
|
345 |
RETURN (__MKSMALLINT(val)); |
611 | 346 |
} |
347 |
oops: |
|
1133 | 348 |
value = __MKSMALLINT(val); |
611 | 349 |
%} |
350 |
. |
|
351 |
"fall-back for non-string streams - we have to continue where |
|
352 |
above primitive left off, in case of a large integer ... |
|
353 |
(instead of doing a super nextDecimalInteger)" |
|
354 |
||
355 |
nextOne := self peek. |
|
356 |
[nextOne notNil and:[nextOne isDigitRadix:10]] whileTrue:[ |
|
357 |
value = (value * 10) + nextOne digitValue. |
|
358 |
nextOne := self nextPeek |
|
359 |
]. |
|
360 |
^ value |
|
361 |
! |
|
362 |
||
363 |
nextPeek |
|
364 |
"advance read pointer return the peek element. |
|
365 |
this is equivalent to (self next; peek). |
|
366 |
- tuned for speed on String-Streams for faster scanning" |
|
367 |
||
368 |
%{ /* NOCONTEXT */ |
|
369 |
OBJ coll, l, p; |
|
370 |
||
1133 | 371 |
coll = __INST(collection); |
372 |
p = __INST(position); |
|
373 |
l = __INST(readLimit); |
|
611 | 374 |
|
375 |
if (__isString(coll) && __bothSmallInteger(p, l)) { |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
376 |
REGISTER int pos; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
377 |
unsigned ch; |
611 | 378 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
379 |
pos = __intVal(p); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
380 |
/* make 1-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
381 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
382 |
if ((pos > 0) && (pos < __intVal(l)) && (pos < __stringSize(coll))) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
383 |
pos = pos + 1; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
384 |
ch = __stringVal(coll)[pos-1]; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
385 |
/* make ZeroPosition-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
386 |
pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
387 |
__INST(position) = __MKSMALLINT(pos); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
388 |
RETURN ( __MKCHARACTER(ch) ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
389 |
} |
611 | 390 |
} |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
391 |
%}. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
392 |
((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEnd]. |
611 | 393 |
position := position + 1. |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
394 |
((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEnd]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
395 |
^ collection at:(position + 1 - ZeroPosition) |
611 | 396 |
! |
397 |
||
1 | 398 |
nextSymbol |
399 |
"read the next selector-symbol (i.e. up to non letter-or-digit). |
|
400 |
return a string containing those characters. |
|
59 | 401 |
- tuned for speed on String-Streams for faster scanning" |
1 | 402 |
%{ |
403 |
int pos, limit, sz; |
|
404 |
int len; |
|
13 | 405 |
char buffer[256]; |
406 |
REGISTER unsigned char *cp; |
|
407 |
REGISTER unsigned ch; |
|
252 | 408 |
OBJ coll, p, l; |
1 | 409 |
|
1133 | 410 |
coll = __INST(collection); |
411 |
p = __INST(position); |
|
412 |
l = __INST(readLimit); |
|
252 | 413 |
|
414 |
if (__isString(coll) && __bothSmallInteger(p, l)) { |
|
415 |
||
1133 | 416 |
pos = __intVal(p); |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
417 |
/* make 1-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
418 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
1133 | 419 |
limit = __intVal(l); |
329 | 420 |
sz = __qSize(coll) - OHDR_SIZE; |
202 | 421 |
if (sz < limit) |
422 |
limit = sz; |
|
1133 | 423 |
cp = __stringVal(coll) + pos - 1; |
1 | 424 |
|
202 | 425 |
len = 0; |
426 |
for (;;) { |
|
427 |
if (pos > limit) break; |
|
428 |
ch = *cp; |
|
1 | 429 |
|
202 | 430 |
if (! (((ch >= 'a') && (ch <= 'z')) || |
431 |
((ch >= 'A') && (ch <= 'Z')) || |
|
432 |
((ch >= '0') && (ch <= '9')) || |
|
433 |
(ch == ':'))) |
|
434 |
break; |
|
435 |
buffer[len++] = ch; |
|
436 |
if (len >= (sizeof(buffer)-1)) { |
|
437 |
/* emergency */ |
|
438 |
break; |
|
439 |
} |
|
440 |
pos++; |
|
441 |
cp++; |
|
442 |
} |
|
1 | 443 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
444 |
/* make ZeroPosition-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
445 |
pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
1133 | 446 |
__INST(position) = __MKSMALLINT(pos); |
202 | 447 |
buffer[len] = '\0'; |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1665
diff
changeset
|
448 |
RETURN ( (len != 0) ? __MKSTRING_L(buffer, len) : nil ); |
1 | 449 |
} |
450 |
%} |
|
451 |
. |
|
452 |
^ super nextSymbol |
|
453 |
! |
|
454 |
||
611 | 455 |
peek |
456 |
"return the next element; do NOT advance read pointer. |
|
457 |
return nil, if there is no next element. |
|
458 |
- tuned for a bit more speed on String/ByteArray/Array-Streams" |
|
1 | 459 |
|
460 |
%{ /* NOCONTEXT */ |
|
611 | 461 |
|
462 |
REGISTER int pos; |
|
463 |
unsigned ch; |
|
464 |
OBJ coll; |
|
465 |
OBJ cls, p, l; |
|
1 | 466 |
|
1133 | 467 |
coll = __INST(collection); |
468 |
p = __INST(position); |
|
469 |
l = __INST(readLimit); |
|
252 | 470 |
|
611 | 471 |
if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
1 | 472 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
473 |
pos = __intVal(p); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
474 |
/* make 1-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
475 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
476 |
if (pos <= __intVal(l) && pos > 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
477 |
cls = __qClass(coll); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
478 |
if (cls == @global(String)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
479 |
if (pos <= __stringSize(coll)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
480 |
ch = __stringVal(coll)[pos-1]; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
481 |
RETURN ( __MKCHARACTER(ch) ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
482 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
483 |
} else if (cls == @global(ByteArray)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
484 |
if (pos <= __byteArraySize(coll)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
485 |
ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
486 |
RETURN ( __MKSMALLINT(ch) ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
487 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
488 |
} else if (cls == @global(Array)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
489 |
if (pos <= __arraySize(coll)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
490 |
RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
491 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
492 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
493 |
} |
1 | 494 |
} |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
495 |
%}. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
496 |
((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEnd]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
497 |
^ collection at:(position + 1 - ZeroPosition) |
1 | 498 |
! |
499 |
||
3316 | 500 |
peekOrNil |
501 |
"return the next element; do NOT advance read pointer. |
|
502 |
return nil, if there is no next element. |
|
503 |
This is much like #peek - |
|
504 |
However, unlike #peek, this does not raise an atEnd-query signal - even |
|
505 |
if handled. Instead, nil is returned immediately." |
|
506 |
||
507 |
%{ /* NOCONTEXT */ |
|
508 |
||
509 |
REGISTER int pos; |
|
510 |
unsigned ch; |
|
511 |
OBJ coll; |
|
512 |
OBJ cls, p, l; |
|
513 |
||
514 |
coll = __INST(collection); |
|
515 |
p = __INST(position); |
|
516 |
l = __INST(readLimit); |
|
517 |
||
518 |
if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
|
519 |
||
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
520 |
pos = __intVal(p); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
521 |
/* make 1-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
522 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
523 |
if (pos <= __intVal(l) && pos > 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
524 |
cls = __qClass(coll); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
525 |
if (cls == @global(String)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
526 |
if (pos <= __stringSize(coll)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
527 |
ch = __stringVal(coll)[pos-1]; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
528 |
RETURN ( __MKCHARACTER(ch) ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
529 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
530 |
RETURN ( nil ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
531 |
} else if (cls == @global(ByteArray)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
532 |
if (pos <= __byteArraySize(coll)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
533 |
ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
534 |
RETURN ( __MKSMALLINT(ch) ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
535 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
536 |
RETURN ( nil ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
537 |
} else if (cls == @global(Array)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
538 |
if (pos <= __arraySize(coll)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
539 |
RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
540 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
541 |
RETURN ( nil ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
542 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
543 |
} |
3316 | 544 |
} |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
545 |
%}. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
546 |
((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ nil]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
547 |
^ collection at:(position + 1 - ZeroPosition) |
3316 | 548 |
! |
549 |
||
1 | 550 |
skipSeparators |
551 |
"skip all whitespace; next will return next non-white-space element. |
|
59 | 552 |
Return the peeked character or nil, if the end-of-stream was reached. |
2 | 553 |
- reimplemented for speed on String-Streams for faster scanning" |
1 | 554 |
|
555 |
%{ /* NOCONTEXT */ |
|
252 | 556 |
OBJ coll, p, l; |
1 | 557 |
|
1133 | 558 |
coll = __INST(collection); |
559 |
p = __INST(position); |
|
560 |
l = __INST(readLimit); |
|
252 | 561 |
|
562 |
if (__isString(coll) && __bothSmallInteger(p, l)) { |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
563 |
REGISTER unsigned char *chars; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
564 |
REGISTER unsigned ch; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
565 |
REGISTER int pos; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
566 |
int limit; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
567 |
int sz; |
1 | 568 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
569 |
pos = __intVal(p); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
570 |
/* make 1-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
571 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
572 |
if (pos <= 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
573 |
RETURN ( nil ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
574 |
} |
1 | 575 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
576 |
limit = __intVal(l); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
577 |
sz = __qSize(coll) - OHDR_SIZE; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
578 |
if (limit > sz) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
579 |
limit = sz; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
580 |
} |
1 | 581 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
582 |
chars = (unsigned char *)(__stringVal(coll) + pos - 1); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
583 |
while (pos <= limit) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
584 |
pos++; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
585 |
ch = *chars++; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
586 |
if ((ch > 0x20) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
587 |
|| ((ch != ' ') |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
588 |
&& (ch != '\t') |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
589 |
&& (ch != '\r') |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
590 |
&& (ch != '\n') |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
591 |
&& (ch != '\f') |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
592 |
&& (ch != 0x0B))) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
593 |
/* make ZeroPosition-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
594 |
pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
595 |
__INST(position) = __MKSMALLINT(pos-1); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
596 |
RETURN ( __MKCHARACTER(ch) ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
597 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
598 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
599 |
/* make ZeroPosition-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
600 |
pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
601 |
__INST(position) = __MKSMALLINT(pos); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
602 |
RETURN ( nil ); |
1 | 603 |
} |
1406 | 604 |
%}. |
1 | 605 |
^ super skipSeparators |
1406 | 606 |
|
607 |
" |
|
608 |
|s| |
|
609 |
||
610 |
s := ' hello world ' readStream. |
|
611 |
s skipSeparators. |
|
612 |
s next. |
|
613 |
" |
|
1 | 614 |
! |
615 |
||
13 | 616 |
skipSeparatorsExceptCR |
617 |
"skip all whitespace except newlines; |
|
202 | 618 |
next will return next non-white-space element. |
619 |
- reimplemented for speed on String-Streams for faster scanning" |
|
620 |
||
13 | 621 |
%{ /* NOCONTEXT */ |
622 |
||
252 | 623 |
OBJ coll, p, l; |
624 |
||
1133 | 625 |
coll = __INST(collection); |
626 |
p = __INST(position); |
|
627 |
l = __INST(readLimit); |
|
252 | 628 |
|
629 |
if (__isString(coll) && __bothSmallInteger(p, l)) { |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
630 |
REGISTER unsigned char *chars; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
631 |
REGISTER unsigned ch; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
632 |
REGISTER int pos; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
633 |
int limit; |
13 | 634 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
635 |
pos = __intVal(p); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
636 |
/* make 1-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
637 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
638 |
if (pos <= 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
639 |
RETURN ( nil ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
640 |
} |
2162
7e1601f633b6
ff is a separator too (in #skipSeparators*)
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
641 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
642 |
limit = __intVal(l); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
643 |
if (limit > (__qSize(coll) - OHDR_SIZE)) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
644 |
limit = __qSize(coll) - OHDR_SIZE; |
13 | 645 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
646 |
chars = (unsigned char *)(__stringVal(coll) + pos - 1); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
647 |
while (pos <= limit) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
648 |
ch = *chars++; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
649 |
if (((int)ch > 0x20) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
650 |
|| ( |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
651 |
(ch != ' ') |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
652 |
&& (ch != '\t') |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
653 |
&& (ch != '\f') |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
654 |
&& (ch != '\b') |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
655 |
&& (ch != 0x0B))) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
656 |
/* make ZeroPosition-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
657 |
pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
658 |
__INST(position) = __MKSMALLINT(pos); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
659 |
RETURN ( __MKCHARACTER(ch) ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
660 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
661 |
pos++; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
662 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
663 |
/* make ZeroPosition-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
664 |
pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
665 |
__INST(position) = __MKSMALLINT(pos); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
666 |
RETURN ( nil ); |
13 | 667 |
} |
668 |
%} |
|
669 |
. |
|
670 |
^ super skipSeparatorsExceptCR |
|
671 |
! |
|
672 |
||
611 | 673 |
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
|
674 |
"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
|
675 |
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
|
676 |
otherwise (i.e. if not found) return nil and leave the stream positioned at the end. |
611 | 677 |
On success, the next read operation will return the element after anObject. |
678 |
- reimplemented for speed on String-Streams for faster scanning" |
|
679 |
||
680 |
%{ /* NOCONTEXT */ |
|
681 |
OBJ coll, p, l; |
|
682 |
||
1133 | 683 |
coll = __INST(collection); |
684 |
p = __INST(position); |
|
685 |
l = __INST(readLimit); |
|
611 | 686 |
|
687 |
if (__isString(coll) |
|
688 |
&& __isCharacter(anObject) |
|
689 |
&& __bothSmallInteger(p, l)) { |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
690 |
REGISTER unsigned char *chars; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
691 |
REGISTER int pos, limit; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
692 |
unsigned ch; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
693 |
int sz; |
611 | 694 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
695 |
pos = __intVal(p); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
696 |
/* make 1-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
697 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
698 |
if (pos <= 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
699 |
RETURN ( nil ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
700 |
} |
611 | 701 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
702 |
limit = __intVal(l); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
703 |
sz = __stringSize(coll); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
704 |
if (limit > sz) limit = sz; |
611 | 705 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
706 |
chars = (unsigned char *)(__stringVal(coll) + pos - 1); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
707 |
ch = __intVal(_characterVal(anObject)) & 0xFF; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
708 |
while (pos < limit) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
709 |
if (*chars == ch) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
710 |
ch = *++chars; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
711 |
pos++; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
712 |
/* make ZeroPosition-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
713 |
pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
714 |
__INST(position) = __MKSMALLINT(pos); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
715 |
RETURN ( self ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
716 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
717 |
chars++; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
718 |
pos++; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
719 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
720 |
/* make ZeroPosition-based */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
721 |
pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
722 |
__INST(position) = __MKSMALLINT(pos+1); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6814
diff
changeset
|
723 |
RETURN ( nil ); |
611 | 724 |
} |
6011
3b91d7834ca5
fixed: skipThrough dod not position atEnd if the element was not found.
Claus Gittinger <cg@exept.de>
parents:
5810
diff
changeset
|
725 |
%}. |
611 | 726 |
^ super skipThrough:anObject |
1 | 727 |
! ! |
728 |
||
59 | 729 |
!ReadStream methodsFor:'writing'! |
1 | 730 |
|
731 |
nextPut:anElement |
|
10 | 732 |
"catch write access to readstreams - report an error" |
733 |
||
734 |
self shouldNotImplement |
|
1 | 735 |
! ! |
611 | 736 |
|
2162
7e1601f633b6
ff is a separator too (in #skipSeparators*)
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
737 |
!ReadStream class methodsFor:'documentation'! |
701 | 738 |
|
739 |
version |
|
7114 | 740 |
^ '$Header: /cvs/stx/stx/libbasic/ReadStream.st,v 1.47 2003-03-17 16:45:48 cg Exp $' |
701 | 741 |
! ! |