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