101 "return the emphasis of the current (i.e. next returned by #next) |
101 "return the emphasis of the current (i.e. next returned by #next) |
102 element. Streams on a string will return nil for all elements. |
102 element. Streams on a string will return nil for all elements. |
103 Streams on collections which nothing at all about emphasises, |
103 Streams on collections which nothing at all about emphasises, |
104 will report an error." |
104 will report an error." |
105 |
105 |
106 ^ collection emphasisAt:(position - ZeroPosition + 1). |
106 ^ collection emphasisAt:(position + 1). |
107 |
107 |
108 " |
108 " |
109 |t s| |
109 |t s| |
110 |
110 |
111 t := 'hello world' asText |
111 t := 'hello world' asText |
112 emphasizeFrom:1 to:5 with:#bold; |
112 emphasizeFrom:1 to:5 with:#bold; |
113 emphasizeFrom:7 to:11 with:#italic. |
113 emphasizeFrom:7 to:11 with:#italic. |
114 |
114 |
115 s := t readStream. |
115 s := t readStream. |
116 [s atEnd] whileFalse:[ |
116 [s atEnd] whileFalse:[ |
117 Transcript show:(s emphasis); show:' '. |
117 Transcript show:(s emphasis); show:' '. |
118 Transcript show:''''; show:(s next); showCR:''''. |
118 Transcript show:''''; show:(s next); showCR:''''. |
119 ]. |
119 ]. |
120 " |
120 " |
121 |
121 |
122 "Modified: 15.5.1996 / 17:30:33 / cg" |
122 "Modified: 15.5.1996 / 17:30:33 / cg" |
123 ! ! |
123 ! ! |
169 p = __INST(position); |
169 p = __INST(position); |
170 l = __INST(readLimit); |
170 l = __INST(readLimit); |
171 |
171 |
172 if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
172 if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
173 |
173 |
174 pos = __intVal(p); |
174 pos = __intVal(p); |
175 /* make 1-based */ |
175 /* make 1-based */ |
176 pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
176 pos = pos + 1; |
177 if (pos > 0 && pos <= __intVal(l)) { |
177 if (pos > 0 && pos <= __intVal(l)) { |
178 OBJ cls, ret; |
178 OBJ cls, ret; |
179 |
179 |
180 cls = __qClass(coll); |
180 cls = __qClass(coll); |
181 if (cls == @global(String)) { |
181 if (cls == @global(String)) { |
182 if (pos <= __stringSize(coll)) { |
182 if (pos <= __stringSize(coll)) { |
183 ch = __stringVal(coll)[pos-1]; |
183 ch = __stringVal(coll)[pos-1]; |
184 ret = __MKCHARACTER(ch); |
184 ret = __MKCHARACTER(ch); |
185 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
185 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
186 RETURN ( ret ); |
186 RETURN ( ret ); |
187 } |
187 } |
188 } else if (cls == @global(ByteArray)) { |
188 } else if (cls == @global(ByteArray)) { |
189 if (pos <= __byteArraySize(coll)) { |
189 if (pos <= __byteArraySize(coll)) { |
190 ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
190 ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
191 ret = __mkSmallInteger(ch); |
191 ret = __mkSmallInteger(ch); |
192 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
192 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
193 RETURN ( ret ); |
193 RETURN ( ret ); |
194 } |
194 } |
195 } else if (cls == @global(Unicode16String)) { |
195 } else if (cls == @global(Unicode16String)) { |
196 if (pos <= __unicode16StringSize(coll)) { |
196 if (pos <= __unicode16StringSize(coll)) { |
197 ch = __Unicode16StringInstPtr(coll)->s_element[pos-1]; |
197 ch = __Unicode16StringInstPtr(coll)->s_element[pos-1]; |
198 ret = __MKUCHARACTER(ch); |
198 ret = __MKUCHARACTER(ch); |
199 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
199 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
200 RETURN ( ret ); |
200 RETURN ( ret ); |
201 } |
201 } |
202 } else if (cls == @global(Array)) { |
202 } else if (cls == @global(Array)) { |
203 if (pos <= __arraySize(coll)) { |
203 if (pos <= __arraySize(coll)) { |
204 ret = __ArrayInstPtr(coll)->a_element[pos-1]; |
204 ret = __ArrayInstPtr(coll)->a_element[pos-1]; |
205 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
205 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
206 RETURN ( ret ); |
206 RETURN ( ret ); |
207 } |
207 } |
208 } |
208 } |
209 } |
209 } |
210 } |
210 } |
211 %}. |
211 %}. |
212 ((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEndRead]. |
212 ((position + 1) > readLimit) ifTrue:[^ self pastEndRead]. |
213 ret := collection at:(position + 1 - ZeroPosition). |
213 ret := collection at:(position + 1). |
214 position := position + 1. |
214 position := position + 1. |
215 ^ ret |
215 ^ ret |
216 ! |
216 ! |
217 |
217 |
218 next:count |
218 next:count |
220 which depends on the streams type - (see #contentsSpecies)." |
220 which depends on the streams type - (see #contentsSpecies)." |
221 |
221 |
222 |answer| |
222 |answer| |
223 |
223 |
224 self contentsSpecies = collection class ifTrue:[ |
224 self contentsSpecies = collection class ifTrue:[ |
225 ((position + count - ZeroPosition) > readLimit) ifFalse:[ |
225 ((position + count) > readLimit) ifFalse:[ |
226 answer := collection copyFrom:position+1 to:position+count. |
226 answer := collection copyFrom:position+1 to:position+count. |
227 position := position+count. |
227 position := position+count. |
228 ^ answer |
228 ^ answer |
229 ]. |
229 ]. |
230 ]. |
230 ]. |
231 ^ super next:count |
231 ^ super next:count |
232 |
232 |
233 " |
233 " |
234 #[1 2 3 4 5 6 7 8 9] readStream |
234 #[1 2 3 4 5 6 7 8 9] readStream |
235 next; |
235 next; |
236 next:5; |
236 next:5; |
237 next. |
237 next. |
238 " |
238 " |
239 ! |
239 ! |
240 |
240 |
241 nextAlphaNumericWord |
241 nextAlphaNumericWord |
242 "read the next word (i.e. up to non letter-or-digit). |
242 "read the next word (i.e. up to non letter-or-digit). |
327 p = __INST(position); |
327 p = __INST(position); |
328 l = __INST(readLimit); |
328 l = __INST(readLimit); |
329 |
329 |
330 if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
330 if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
331 |
331 |
332 pos = __intVal(p); |
332 pos = __intVal(p); |
333 /* make 1-based */ |
333 /* make 1-based */ |
334 pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
334 pos = pos + 1; |
335 if (pos > 0 && pos <= __intVal(l)) { |
335 if (pos > 0 && pos <= __intVal(l)) { |
336 OBJ cls, ret; |
336 OBJ cls, ret; |
337 |
337 |
338 cls = __qClass(coll); |
338 cls = __qClass(coll); |
339 if (cls == @global(String)) { |
339 if (cls == @global(String)) { |
340 if (pos <= __stringSize(coll)) { |
340 if (pos <= __stringSize(coll)) { |
341 ch = __stringVal(coll)[pos-1]; |
341 ch = __stringVal(coll)[pos-1]; |
342 ret = __mkSmallInteger(ch); |
342 ret = __mkSmallInteger(ch); |
343 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
343 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
344 RETURN ( ret ); |
344 RETURN ( ret ); |
345 } |
345 } |
346 } else if (cls == @global(ByteArray)) { |
346 } else if (cls == @global(ByteArray)) { |
347 if (pos <= __byteArraySize(coll)) { |
347 if (pos <= __byteArraySize(coll)) { |
348 ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
348 ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
349 ret = __mkSmallInteger(ch); |
349 ret = __mkSmallInteger(ch); |
350 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
350 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
351 RETURN ( ret ); |
351 RETURN ( ret ); |
352 } |
352 } |
353 } else if (cls == @global(Array)) { |
353 } else if (cls == @global(Array)) { |
354 if (pos <= __arraySize(coll)) { |
354 if (pos <= __arraySize(coll)) { |
355 ret = __ArrayInstPtr(coll)->a_element[pos-1]; |
355 ret = __ArrayInstPtr(coll)->a_element[pos-1]; |
356 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
356 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
357 RETURN ( ret ); |
357 RETURN ( ret ); |
358 } |
358 } |
359 } |
359 } |
360 } |
360 } |
361 } |
361 } |
362 %}. |
362 %}. |
363 ((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEndRead]. |
363 ((position + 1) > readLimit) ifTrue:[^ self pastEndRead]. |
364 ret := collection at:(position + 1 -ZeroPosition). |
364 ret := collection at:(position + 1). |
365 position := position + 1. |
365 position := position + 1. |
366 ^ ret asInteger |
366 ^ ret asInteger |
367 ! |
367 ! |
368 |
368 |
369 nextBytes:numBytes into:aCollection startingAt:initialIndex |
369 nextBytes:numBytes into:aCollection startingAt:initialIndex |
478 coll = __INST(collection); |
478 coll = __INST(collection); |
479 p = __INST(position); |
479 p = __INST(position); |
480 l = __INST(readLimit); |
480 l = __INST(readLimit); |
481 |
481 |
482 if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
482 if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
483 pos = __intVal(p); |
483 pos = __intVal(p); |
484 /* make 1-based */ |
484 /* make 1-based */ |
485 pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
485 pos = pos + 1; |
486 if (pos > 0) { |
486 if (pos > 0) { |
487 OBJ cls, ret; |
487 OBJ cls, ret; |
488 |
488 |
489 if (pos > __intVal(l)) { |
489 if (pos > __intVal(l)) { |
490 RETURN(nil); |
490 RETURN(nil); |
491 } |
491 } |
492 |
492 |
493 cls = __qClass(coll); |
493 cls = __qClass(coll); |
494 if (cls == @global(String)) { |
494 if (cls == @global(String)) { |
495 if (pos <= __stringSize(coll)) { |
495 if (pos <= __stringSize(coll)) { |
496 ch = __stringVal(coll)[pos-1]; |
496 ch = __stringVal(coll)[pos-1]; |
497 ret = __MKCHARACTER(ch); |
497 ret = __MKCHARACTER(ch); |
498 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
498 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
499 RETURN ( ret ); |
499 RETURN ( ret ); |
500 } |
500 } |
501 } else if (cls == @global(ByteArray)) { |
501 } else if (cls == @global(ByteArray)) { |
502 if (pos <= __byteArraySize(coll)) { |
502 if (pos <= __byteArraySize(coll)) { |
503 ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
503 ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
504 ret = __mkSmallInteger(ch); |
504 ret = __mkSmallInteger(ch); |
505 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
505 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
506 RETURN ( ret ); |
506 RETURN ( ret ); |
507 } |
507 } |
508 } else if (cls == @global(Unicode16String)) { |
508 } else if (cls == @global(Unicode16String)) { |
509 if (pos <= __unicode16StringSize(coll)) { |
509 if (pos <= __unicode16StringSize(coll)) { |
510 ch = __Unicode16StringInstPtr(coll)->s_element[pos-1]; |
510 ch = __Unicode16StringInstPtr(coll)->s_element[pos-1]; |
511 ret = __MKUCHARACTER(ch); |
511 ret = __MKUCHARACTER(ch); |
512 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
512 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
513 RETURN ( ret ); |
513 RETURN ( ret ); |
514 } |
514 } |
515 } else if (cls == @global(Array)) { |
515 } else if (cls == @global(Array)) { |
516 if (pos <= __arraySize(coll)) { |
516 if (pos <= __arraySize(coll)) { |
517 ret = __ArrayInstPtr(coll)->a_element[pos-1]; |
517 ret = __ArrayInstPtr(coll)->a_element[pos-1]; |
518 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
518 __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1); |
519 RETURN ( ret ); |
519 RETURN ( ret ); |
520 } |
520 } |
521 } |
521 } |
522 } |
522 } |
523 } |
523 } |
524 %}. |
524 %}. |
525 ret := collection at:(position + 1 - ZeroPosition). |
525 ret := collection at:(position + 1). |
526 position := position + 1. |
526 position := position + 1. |
527 ^ ret |
527 ^ ret |
528 ! |
528 ! |
529 |
529 |
530 nextPeek |
530 nextPeek |
538 coll = __INST(collection); |
538 coll = __INST(collection); |
539 p = __INST(position); |
539 p = __INST(position); |
540 l = __INST(readLimit); |
540 l = __INST(readLimit); |
541 |
541 |
542 if (__isStringLike(coll) && __bothSmallInteger(p, l)) { |
542 if (__isStringLike(coll) && __bothSmallInteger(p, l)) { |
543 REGISTER int pos; |
543 REGISTER int pos; |
544 unsigned ch; |
544 unsigned ch; |
545 |
545 |
546 pos = __intVal(p); |
546 pos = __intVal(p); |
547 /* make 1-based */ |
547 /* make 1-based */ |
548 pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
548 pos = pos + 1; |
549 if ((pos > 0) && (pos < __intVal(l)) && (pos < __stringSize(coll))) { |
549 if ((pos > 0) && (pos < __intVal(l)) && (pos < __stringSize(coll))) { |
550 pos = pos + 1; |
550 pos = pos + 1; |
551 ch = __stringVal(coll)[pos-1]; |
551 ch = __stringVal(coll)[pos-1]; |
552 /* make ZeroPosition-based */ |
552 /* make ZeroPosition-based */ |
553 pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition)); |
553 pos = pos - 1; |
554 __INST(position) = __mkSmallInteger(pos); |
554 __INST(position) = __mkSmallInteger(pos); |
555 RETURN ( __MKCHARACTER(ch) ); |
555 RETURN ( __MKCHARACTER(ch) ); |
556 } |
556 } |
557 } |
557 } |
558 %}. |
558 %}. |
559 ((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEndRead]. |
559 ((position + 1) > readLimit) ifTrue:[^ self pastEndRead]. |
560 position := position + 1. |
560 position := position + 1. |
561 ((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEndRead]. |
561 ((position + 1) > readLimit) ifTrue:[^ self pastEndRead]. |
562 ^ collection at:(position + 1 - ZeroPosition) |
562 ^ collection at:(position + 1) |
563 ! |
563 ! |
564 |
564 |
565 peek |
565 peek |
566 "return the next element; do NOT advance read pointer. |
566 "return the next element; do NOT advance read pointer. |
567 return nil, if there is no next element. |
567 return nil, if there is no next element. |
578 p = __INST(position); |
578 p = __INST(position); |
579 l = __INST(readLimit); |
579 l = __INST(readLimit); |
580 |
580 |
581 if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
581 if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
582 |
582 |
583 pos = __intVal(p); |
583 pos = __intVal(p); |
584 /* make 1-based */ |
584 /* make 1-based */ |
585 pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
585 pos = pos + 1; |
586 if (pos <= __intVal(l) && pos > 0) { |
586 if (pos <= __intVal(l) && pos > 0) { |
587 cls = __qClass(coll); |
587 cls = __qClass(coll); |
588 if (cls == @global(String)) { |
588 if (cls == @global(String)) { |
589 if (pos <= __stringSize(coll)) { |
589 if (pos <= __stringSize(coll)) { |
590 ch = __stringVal(coll)[pos-1]; |
590 ch = __stringVal(coll)[pos-1]; |
591 RETURN ( __MKCHARACTER(ch) ); |
591 RETURN ( __MKCHARACTER(ch) ); |
592 } |
592 } |
593 } else if (cls == @global(ByteArray)) { |
593 } else if (cls == @global(ByteArray)) { |
594 if (pos <= __byteArraySize(coll)) { |
594 if (pos <= __byteArraySize(coll)) { |
595 ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
595 ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
596 RETURN ( __mkSmallInteger(ch) ); |
596 RETURN ( __mkSmallInteger(ch) ); |
597 } |
597 } |
598 } else if (cls == @global(Array)) { |
598 } else if (cls == @global(Array)) { |
599 if (pos <= __arraySize(coll)) { |
599 if (pos <= __arraySize(coll)) { |
600 RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]); |
600 RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]); |
601 } |
601 } |
602 } |
602 } |
603 } |
603 } |
604 } |
604 } |
605 %}. |
605 %}. |
606 ((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEndRead]. |
606 ((position + 1) > readLimit) ifTrue:[^ self pastEndRead]. |
607 ^ collection at:(position + 1 - ZeroPosition) |
607 ^ collection at:(position + 1) |
608 ! |
608 ! |
609 |
609 |
610 peekOrNil |
610 peekOrNil |
611 "return the next element; do NOT advance read pointer. |
611 "return the next element; do NOT advance read pointer. |
612 return nil, if there is no next element. |
612 return nil, if there is no next element. |
625 p = __INST(position); |
625 p = __INST(position); |
626 l = __INST(readLimit); |
626 l = __INST(readLimit); |
627 |
627 |
628 if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
628 if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) { |
629 |
629 |
630 pos = __intVal(p); |
630 pos = __intVal(p); |
631 /* make 1-based */ |
631 /* make 1-based */ |
632 pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
632 pos = pos + 1; |
633 if (pos <= __intVal(l) && pos > 0) { |
633 if (pos <= __intVal(l) && pos > 0) { |
634 cls = __qClass(coll); |
634 cls = __qClass(coll); |
635 if (cls == @global(String)) { |
635 if (cls == @global(String)) { |
636 if (pos <= __stringSize(coll)) { |
636 if (pos <= __stringSize(coll)) { |
637 ch = __stringVal(coll)[pos-1]; |
637 ch = __stringVal(coll)[pos-1]; |
638 RETURN ( __MKCHARACTER(ch) ); |
638 RETURN ( __MKCHARACTER(ch) ); |
639 } |
639 } |
640 RETURN ( nil ); |
640 RETURN ( nil ); |
641 } else if (cls == @global(ByteArray)) { |
641 } else if (cls == @global(ByteArray)) { |
642 if (pos <= __byteArraySize(coll)) { |
642 if (pos <= __byteArraySize(coll)) { |
643 ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
643 ch = __ByteArrayInstPtr(coll)->ba_element[pos-1]; |
644 RETURN ( __mkSmallInteger(ch) ); |
644 RETURN ( __mkSmallInteger(ch) ); |
645 } |
645 } |
646 RETURN ( nil ); |
646 RETURN ( nil ); |
647 } else if (cls == @global(Array)) { |
647 } else if (cls == @global(Array)) { |
648 if (pos <= __arraySize(coll)) { |
648 if (pos <= __arraySize(coll)) { |
649 RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]); |
649 RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]); |
650 } |
650 } |
651 RETURN ( nil ); |
651 RETURN ( nil ); |
652 } |
652 } |
653 } |
653 } |
654 } |
654 } |
655 %}. |
655 %}. |
656 ((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ nil]. |
656 ((position + 1) > readLimit) ifTrue:[^ nil]. |
657 ^ collection at:(position + 1 - ZeroPosition) |
657 ^ collection at:(position + 1) |
658 ! |
658 ! |
659 |
659 |
660 skipSeparators |
660 skipSeparators |
661 "skip all whitespace; next will return next non-white-space element. |
661 "skip all whitespace; next will return next non-white-space element. |
662 Return the peeked character or nil, if the end-of-stream was reached. |
662 Return the peeked character or nil, if the end-of-stream was reached. |