69 |
69 |
70 REGISTER int pos; |
70 REGISTER int pos; |
71 unsigned ch; |
71 unsigned ch; |
72 OBJ coll, p, l; |
72 OBJ coll, p, l; |
73 |
73 |
74 coll = _INST(collection); |
74 coll = __INST(collection); |
75 p = _INST(position); |
75 p = __INST(position); |
76 l = _INST(readLimit); |
76 l = __INST(readLimit); |
77 |
77 |
78 if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
78 if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
79 |
79 |
80 pos = _intVal(p); |
80 pos = __intVal(p); |
81 if (pos > 0 && pos <= _intVal(l)) { |
81 if (pos > 0 && pos <= __intVal(l)) { |
82 OBJ cls; |
82 OBJ cls; |
83 |
83 |
84 cls = __qClass(coll); |
84 cls = __qClass(coll); |
85 if (cls == String) { |
85 if (cls == @global(String)) { |
86 if (pos <= _stringSize(coll)) { |
86 if (pos <= __stringSize(coll)) { |
87 _INST(position) = _MKSMALLINT(pos + 1); |
87 __INST(position) = __MKSMALLINT(pos + 1); |
88 ch = _stringVal(coll)[pos-1]; |
88 ch = __stringVal(coll)[pos-1]; |
89 RETURN ( _MKCHARACTER(ch) ); |
89 RETURN ( __MKCHARACTER(ch) ); |
90 } |
90 } |
91 } else if (cls == ByteArray) { |
91 } else if (cls == @global(ByteArray)) { |
92 if (pos <= _byteArraySize(coll)) { |
92 if (pos <= __byteArraySize(coll)) { |
93 _INST(position) = _MKSMALLINT(pos + 1); |
93 __INST(position) = __MKSMALLINT(pos + 1); |
94 ch = _ByteArrayInstPtr(coll)->ba_element[pos-1]; |
94 ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
95 RETURN ( _MKSMALLINT(ch) ); |
95 RETURN ( __MKSMALLINT(ch) ); |
96 } |
96 } |
97 } else if (cls == Array) { |
97 } else if (cls == @global(Array)) { |
98 if (pos <= _arraySize(coll)) { |
98 if (pos <= __arraySize(coll)) { |
99 _INST(position) = _MKSMALLINT(pos + 1); |
99 __INST(position) = __MKSMALLINT(pos + 1); |
100 RETURN ( _ArrayInstPtr(coll)->a_element[pos-1]); |
100 RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]); |
101 } |
101 } |
102 } |
102 } |
103 } |
103 } |
104 } |
104 } |
105 %} |
105 %} |
123 REGISTER unsigned char *cp; |
123 REGISTER unsigned char *cp; |
124 REGISTER unsigned ch; |
124 REGISTER unsigned ch; |
125 OBJ coll, p, l; |
125 OBJ coll, p, l; |
126 OBJ __MKSTRING_L(); |
126 OBJ __MKSTRING_L(); |
127 |
127 |
128 coll = _INST(collection); |
128 coll = __INST(collection); |
129 p = _INST(position); |
129 p = __INST(position); |
130 l = _INST(readLimit); |
130 l = __INST(readLimit); |
131 |
131 |
132 if (__isString(coll) && __bothSmallInteger(p, l)) { |
132 if (__isString(coll) && __bothSmallInteger(p, l)) { |
133 |
133 |
134 pos = _intVal(p); |
134 pos = __intVal(p); |
135 limit = _intVal(l); |
135 limit = __intVal(l); |
136 sz = __qSize(coll) - OHDR_SIZE; |
136 sz = __qSize(coll) - OHDR_SIZE; |
137 if (sz < limit) |
137 if (sz < limit) |
138 limit = sz; |
138 limit = sz; |
139 cp = _stringVal(coll) + pos - 1; |
139 cp = __stringVal(coll) + pos - 1; |
140 |
140 |
141 for (;;) { |
141 for (;;) { |
142 if (pos > limit) break; |
142 if (pos > limit) break; |
143 ch = *cp; |
143 ch = *cp; |
144 |
144 |
186 REGISTER unsigned char *cp; |
186 REGISTER unsigned char *cp; |
187 REGISTER unsigned ch; |
187 REGISTER unsigned ch; |
188 int val = 0; |
188 int val = 0; |
189 OBJ coll, p, l; |
189 OBJ coll, p, l; |
190 |
190 |
191 coll = _INST(collection); |
191 coll = __INST(collection); |
192 p = _INST(position); |
192 p = __INST(position); |
193 l = _INST(readLimit); |
193 l = __INST(readLimit); |
194 |
194 |
195 if (__isString(coll) && __bothSmallInteger(p, l)) { |
195 if (__isString(coll) && __bothSmallInteger(p, l)) { |
196 |
196 |
197 pos = _intVal(p); |
197 pos = __intVal(p); |
198 limit = _intVal(l); |
198 limit = __intVal(l); |
199 sz = __qSize(coll) - OHDR_SIZE; |
199 sz = __qSize(coll) - OHDR_SIZE; |
200 if (sz < limit) |
200 if (sz < limit) |
201 limit = sz; |
201 limit = sz; |
202 cp = _stringVal(coll) + pos - 1; |
202 cp = __stringVal(coll) + pos - 1; |
203 |
203 |
204 for (;;) { |
204 for (;;) { |
205 if (pos > limit) break; |
205 if (pos > limit) break; |
206 ch = *cp; |
206 ch = *cp; |
207 |
207 |
209 val = val * 10 + (ch - '0'); |
209 val = val * 10 + (ch - '0'); |
210 pos++; |
210 pos++; |
211 if (val > (_MAX_INT / 10)) goto oops; |
211 if (val > (_MAX_INT / 10)) goto oops; |
212 cp++; |
212 cp++; |
213 } |
213 } |
214 _INST(position) = _MKSMALLINT(pos); |
214 __INST(position) = __MKSMALLINT(pos); |
215 return _MKSMALLINT(val); |
215 return __MKSMALLINT(val); |
216 } |
216 } |
217 oops: |
217 oops: |
218 value = _MKSMALLINT(val); |
218 value = __MKSMALLINT(val); |
219 %} |
219 %} |
220 . |
220 . |
221 "fall-back for non-string streams - we have to continue where |
221 "fall-back for non-string streams - we have to continue where |
222 above primitive left off, in case of a large integer ... |
222 above primitive left off, in case of a large integer ... |
223 (instead of doing a super nextDecimalInteger)" |
223 (instead of doing a super nextDecimalInteger)" |
236 - tuned for speed on String-Streams for faster scanning" |
236 - tuned for speed on String-Streams for faster scanning" |
237 |
237 |
238 %{ /* NOCONTEXT */ |
238 %{ /* NOCONTEXT */ |
239 OBJ coll, l, p; |
239 OBJ coll, l, p; |
240 |
240 |
241 coll = _INST(collection); |
241 coll = __INST(collection); |
242 p = _INST(position); |
242 p = __INST(position); |
243 l = _INST(readLimit); |
243 l = __INST(readLimit); |
244 |
244 |
245 if (__isString(coll) && __bothSmallInteger(p, l)) { |
245 if (__isString(coll) && __bothSmallInteger(p, l)) { |
246 REGISTER int pos; |
246 REGISTER int pos; |
247 unsigned ch; |
247 unsigned ch; |
248 |
248 |
249 pos = _intVal(p); |
249 pos = __intVal(p); |
250 if ((pos > 0) && (pos < _intVal(l)) && (pos < _stringSize(coll))) { |
250 if ((pos > 0) && (pos < __intVal(l)) && (pos < __stringSize(coll))) { |
251 pos += 1; |
251 pos += 1; |
252 _INST(position) = _MKSMALLINT(pos); |
252 __INST(position) = __MKSMALLINT(pos); |
253 ch = _stringVal(coll)[pos-1]; |
253 ch = __stringVal(coll)[pos-1]; |
254 RETURN ( _MKCHARACTER(ch) ); |
254 RETURN ( __MKCHARACTER(ch) ); |
255 } |
255 } |
256 } |
256 } |
257 %} |
257 %} |
258 . |
258 . |
259 (position > readLimit) ifTrue:[^ self pastEnd]. |
259 (position > readLimit) ifTrue:[^ self pastEnd]. |
273 REGISTER unsigned char *cp; |
273 REGISTER unsigned char *cp; |
274 REGISTER unsigned ch; |
274 REGISTER unsigned ch; |
275 OBJ coll, p, l; |
275 OBJ coll, p, l; |
276 OBJ __MKSTRING_L(); |
276 OBJ __MKSTRING_L(); |
277 |
277 |
278 coll = _INST(collection); |
278 coll = __INST(collection); |
279 p = _INST(position); |
279 p = __INST(position); |
280 l = _INST(readLimit); |
280 l = __INST(readLimit); |
281 |
281 |
282 if (__isString(coll) && __bothSmallInteger(p, l)) { |
282 if (__isString(coll) && __bothSmallInteger(p, l)) { |
283 |
283 |
284 pos = _intVal(p); |
284 pos = __intVal(p); |
285 limit = _intVal(l); |
285 limit = __intVal(l); |
286 sz = __qSize(coll) - OHDR_SIZE; |
286 sz = __qSize(coll) - OHDR_SIZE; |
287 if (sz < limit) |
287 if (sz < limit) |
288 limit = sz; |
288 limit = sz; |
289 cp = _stringVal(coll) + pos - 1; |
289 cp = __stringVal(coll) + pos - 1; |
290 |
290 |
291 len = 0; |
291 len = 0; |
292 for (;;) { |
292 for (;;) { |
293 if (pos > limit) break; |
293 if (pos > limit) break; |
294 ch = *cp; |
294 ch = *cp; |
326 REGISTER int pos; |
326 REGISTER int pos; |
327 unsigned ch; |
327 unsigned ch; |
328 OBJ coll; |
328 OBJ coll; |
329 OBJ cls, p, l; |
329 OBJ cls, p, l; |
330 |
330 |
331 coll = _INST(collection); |
331 coll = __INST(collection); |
332 p = _INST(position); |
332 p = __INST(position); |
333 l = _INST(readLimit); |
333 l = __INST(readLimit); |
334 |
334 |
335 if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
335 if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
336 |
336 |
337 pos = _intVal(p); |
337 pos = __intVal(p); |
338 if (pos <= _intVal(l) && pos > 0) { |
338 if (pos <= __intVal(l) && pos > 0) { |
339 cls = __qClass(coll); |
339 cls = __qClass(coll); |
340 if (cls == String) { |
340 if (cls == @global(String)) { |
341 if (pos <= _stringSize(coll)) { |
341 if (pos <= __stringSize(coll)) { |
342 ch = _stringVal(coll)[pos-1]; |
342 ch = __stringVal(coll)[pos-1]; |
343 RETURN ( _MKCHARACTER(ch) ); |
343 RETURN ( __MKCHARACTER(ch) ); |
344 } |
344 } |
345 } else if (cls == ByteArray) { |
345 } else if (cls == @global(ByteArray)) { |
346 if (pos <= _byteArraySize(coll)) { |
346 if (pos <= __byteArraySize(coll)) { |
347 ch = _ByteArrayInstPtr(coll)->ba_element[pos-1]; |
347 ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
348 RETURN ( _MKSMALLINT(ch) ); |
348 RETURN ( __MKSMALLINT(ch) ); |
349 } |
349 } |
350 } else if (cls == Array) { |
350 } else if (cls == @global(Array)) { |
351 if (pos <= _arraySize(coll)) { |
351 if (pos <= __arraySize(coll)) { |
352 RETURN ( _ArrayInstPtr(coll)->a_element[pos-1]); |
352 RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]); |
353 } |
353 } |
354 } |
354 } |
355 } |
355 } |
356 } |
356 } |
357 %} |
357 %} |
366 - reimplemented for speed on String-Streams for faster scanning" |
366 - reimplemented for speed on String-Streams for faster scanning" |
367 |
367 |
368 %{ /* NOCONTEXT */ |
368 %{ /* NOCONTEXT */ |
369 OBJ coll, p, l; |
369 OBJ coll, p, l; |
370 |
370 |
371 coll = _INST(collection); |
371 coll = __INST(collection); |
372 p = _INST(position); |
372 p = __INST(position); |
373 l = _INST(readLimit); |
373 l = __INST(readLimit); |
374 |
374 |
375 if (__isString(coll) && __bothSmallInteger(p, l)) { |
375 if (__isString(coll) && __bothSmallInteger(p, l)) { |
376 REGISTER unsigned char *chars; |
376 REGISTER unsigned char *chars; |
377 REGISTER unsigned ch; |
377 REGISTER unsigned ch; |
378 REGISTER int pos; |
378 REGISTER int pos; |
379 int limit; |
379 int limit; |
380 |
380 |
381 pos = _intVal(p); |
381 pos = __intVal(p); |
382 if (pos <= 0) { |
382 if (pos <= 0) { |
383 RETURN ( nil ); |
383 RETURN ( nil ); |
384 } |
384 } |
385 |
385 |
386 limit = _intVal(l); |
386 limit = __intVal(l); |
387 if (limit > (__qSize(coll) - OHDR_SIZE)) |
387 if (limit > (__qSize(coll) - OHDR_SIZE)) |
388 limit = __qSize(coll) - OHDR_SIZE; |
388 limit = __qSize(coll) - OHDR_SIZE; |
389 |
389 |
390 chars = (unsigned char *)(_stringVal(coll) + pos - 1); |
390 chars = (unsigned char *)(__stringVal(coll) + pos - 1); |
391 while (pos <= limit) { |
391 while (pos <= limit) { |
392 ch = *chars++; |
392 ch = *chars++; |
393 if ((ch != ' ') && (ch != '\t') && (ch != '\r') |
393 if ((ch != ' ') && (ch != '\t') && (ch != '\r') |
394 && (ch != '\n') && (ch != 0x0B)) { |
394 && (ch != '\n') && (ch != 0x0B)) { |
395 _INST(position) = _MKSMALLINT(pos); |
395 __INST(position) = __MKSMALLINT(pos); |
396 RETURN ( _MKCHARACTER(ch) ); |
396 RETURN ( __MKCHARACTER(ch) ); |
397 } |
397 } |
398 pos++; |
398 pos++; |
399 } |
399 } |
400 _INST(position) = _MKSMALLINT(pos); |
400 __INST(position) = __MKSMALLINT(pos); |
401 RETURN ( nil ); |
401 RETURN ( nil ); |
402 } |
402 } |
403 %} |
403 %} |
404 . |
404 . |
405 ^ super skipSeparators |
405 ^ super skipSeparators |
412 |
412 |
413 %{ /* NOCONTEXT */ |
413 %{ /* NOCONTEXT */ |
414 |
414 |
415 OBJ coll, p, l; |
415 OBJ coll, p, l; |
416 |
416 |
417 coll = _INST(collection); |
417 coll = __INST(collection); |
418 p = _INST(position); |
418 p = __INST(position); |
419 l = _INST(readLimit); |
419 l = __INST(readLimit); |
420 |
420 |
421 if (__isString(coll) && __bothSmallInteger(p, l)) { |
421 if (__isString(coll) && __bothSmallInteger(p, l)) { |
422 REGISTER unsigned char *chars; |
422 REGISTER unsigned char *chars; |
423 REGISTER unsigned ch; |
423 REGISTER unsigned ch; |
424 REGISTER int pos; |
424 REGISTER int pos; |
425 int limit; |
425 int limit; |
426 |
426 |
427 pos = _intVal(p); |
427 pos = __intVal(p); |
428 if (pos <= 0) { |
428 if (pos <= 0) { |
429 RETURN ( nil ); |
429 RETURN ( nil ); |
430 } |
430 } |
431 |
431 |
432 limit = _intVal(l); |
432 limit = __intVal(l); |
433 if (limit > (__qSize(coll) - OHDR_SIZE)) |
433 if (limit > (__qSize(coll) - OHDR_SIZE)) |
434 limit = __qSize(coll) - OHDR_SIZE; |
434 limit = __qSize(coll) - OHDR_SIZE; |
435 |
435 |
436 chars = (unsigned char *)(_stringVal(coll) + pos - 1); |
436 chars = (unsigned char *)(__stringVal(coll) + pos - 1); |
437 while (pos <= limit) { |
437 while (pos <= limit) { |
438 ch = *chars++; |
438 ch = *chars++; |
439 if ((ch != ' ') && (ch != '\t') && (ch != '\r') && (ch != 0x0B)) { |
439 if ((ch != ' ') && (ch != '\t') && (ch != '\r') && (ch != 0x0B)) { |
440 _INST(position) = _MKSMALLINT(pos); |
440 __INST(position) = __MKSMALLINT(pos); |
441 RETURN ( _MKCHARACTER(ch) ); |
441 RETURN ( __MKCHARACTER(ch) ); |
442 } |
442 } |
443 pos++; |
443 pos++; |
444 } |
444 } |
445 _INST(position) = _MKSMALLINT(pos); |
445 __INST(position) = __MKSMALLINT(pos); |
446 RETURN ( nil ); |
446 RETURN ( nil ); |
447 } |
447 } |
448 %} |
448 %} |
449 . |
449 . |
450 ^ super skipSeparatorsExceptCR |
450 ^ super skipSeparatorsExceptCR |
457 - reimplemented for speed on String-Streams for faster scanning" |
457 - reimplemented for speed on String-Streams for faster scanning" |
458 |
458 |
459 %{ /* NOCONTEXT */ |
459 %{ /* NOCONTEXT */ |
460 OBJ coll, p, l; |
460 OBJ coll, p, l; |
461 |
461 |
462 coll = _INST(collection); |
462 coll = __INST(collection); |
463 p = _INST(position); |
463 p = __INST(position); |
464 l = _INST(readLimit); |
464 l = __INST(readLimit); |
465 |
465 |
466 if (__isString(coll) |
466 if (__isString(coll) |
467 && __isCharacter(anObject) |
467 && __isCharacter(anObject) |
468 && __bothSmallInteger(p, l)) { |
468 && __bothSmallInteger(p, l)) { |
469 REGISTER unsigned char *chars; |
469 REGISTER unsigned char *chars; |
470 REGISTER int pos, limit; |
470 REGISTER int pos, limit; |
471 unsigned ch; |
471 unsigned ch; |
472 int sz; |
472 int sz; |
473 |
473 |
474 pos = _intVal(p); |
474 pos = __intVal(p); |
475 if (pos <= 0) { |
475 if (pos <= 0) { |
476 RETURN ( nil ); |
476 RETURN ( nil ); |
477 } |
477 } |
478 |
478 |
479 limit = _intVal(l); |
479 limit = __intVal(l); |
480 sz = _stringSize(coll); |
480 sz = __stringSize(coll); |
481 if (limit > sz) limit = sz; |
481 if (limit > sz) limit = sz; |
482 |
482 |
483 chars = (unsigned char *)(_stringVal(coll) + pos - 1); |
483 chars = (unsigned char *)(__stringVal(coll) + pos - 1); |
484 ch = _intVal(_characterVal(anObject)) & 0xFF; |
484 ch = __intVal(_characterVal(anObject)) & 0xFF; |
485 while (pos < limit) { |
485 while (pos < limit) { |
486 if (*chars == ch) { |
486 if (*chars == ch) { |
487 ch = *++chars; |
487 ch = *++chars; |
488 pos++; |
488 pos++; |
489 _INST(position) = _MKSMALLINT(pos); |
489 __INST(position) = __MKSMALLINT(pos); |
490 RETURN ( anObject ); |
490 RETURN ( anObject ); |
491 } |
491 } |
492 chars++; |
492 chars++; |
493 pos++; |
493 pos++; |
494 } |
494 } |