ReadStream.st
changeset 23987 bba7ed9be3c1
parent 23986 27dd00ebc6bd
child 24835 9612a07ed3c2
equal deleted inserted replaced
23986:27dd00ebc6bd 23987:bba7ed9be3c1
   264                     ch = __unicode16StringVal(coll)[pos];
   264                     ch = __unicode16StringVal(coll)[pos];
   265                     ret = __MKUCHARACTER(ch);
   265                     ret = __MKUCHARACTER(ch);
   266                     __INST(position) = __mkSmallInteger(pos+1);
   266                     __INST(position) = __mkSmallInteger(pos+1);
   267                     RETURN ( ret );
   267                     RETURN ( ret );
   268                 }
   268                 }
       
   269             } else if (cls == @global(Array)) {
       
   270                 if (pos < __arraySize(coll)) {
       
   271                     ret = __ArrayInstPtr(coll)->a_element[pos];
       
   272                     __INST(position) = __mkSmallInteger(pos+1);
       
   273                     RETURN ( ret );
       
   274                 }
   269             } else if (cls == @global(Unicode32String)) {
   275             } else if (cls == @global(Unicode32String)) {
   270                 if (pos < __unicode32StringSize(coll)) {
   276                 if (pos < __unicode32StringSize(coll)) {
   271                     ch = __unicode32StringVal(coll)[pos];
   277                     ch = __unicode32StringVal(coll)[pos];
   272                     ret = __MKUCHARACTER(ch);
   278                     ret = __MKUCHARACTER(ch);
   273                     __INST(position) = __mkSmallInteger(pos+1);
   279                     __INST(position) = __mkSmallInteger(pos+1);
   274                     RETURN ( ret );
   280                     RETURN ( ret );
   275                 }
   281                 }
   276             } else if (cls == @global(Array)) {
       
   277                 if (pos < __arraySize(coll)) {
       
   278                     ret = __ArrayInstPtr(coll)->a_element[pos];
       
   279                     __INST(position) = __mkSmallInteger(pos+1);
       
   280                     RETURN ( ret );
       
   281                 }
       
   282             }
   282             }
   283         }
   283         }
   284     }
   284     }
   285 %}.
   285 %}.
   286     (position >= readLimit) ifTrue:[^ self pastEndRead].
   286     (position >= readLimit) ifTrue:[^ self pastEndRead].
   287     position := position + 1.
   287     position := position + 1.
   288     ret := collection at:position.
   288     ret := collection at:position.
   289     ^ ret
   289     ^ ret
   290 
   290 
   291     "Modified: / 27-03-2019 / 15:34:48 / Claus Gittinger"
   291     "Modified: / 27-03-2019 / 15:40:38 / Claus Gittinger"
   292 !
   292 !
   293 
   293 
   294 next:count
   294 next:count
   295     "return the next count elements of the stream as aCollection,
   295     "return the next count elements of the stream as aCollection,
   296      which depends on the streams type - (see #contentsSpecies)."
   296      which depends on the streams type - (see #contentsSpecies)."
   611 
   611 
   612     REGISTER INT pos;
   612     REGISTER INT pos;
   613     unsigned ch;
   613     unsigned ch;
   614     OBJ coll;
   614     OBJ coll;
   615     OBJ cls, p, l;
   615     OBJ cls, p, l;
   616 
   616     INT _readLimit;
   617     coll = __INST(collection);
   617     
   618     p = __INST(position);
   618     p = __INST(position);
   619     l = __INST(readLimit);
   619     l = __INST(readLimit);
       
   620     coll = __INST(collection);
       
   621 
       
   622     pos = __intVal(p);
       
   623     _readLimit = __intVal(l); 
   620 
   624 
   621     if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) {
   625     if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) {
   622 
   626         if ((pos >= 0) && (pos < _readLimit)) {
   623         pos = __intVal(p);
       
   624         if ((pos < __intVal(l)) && (pos >= 0)) {
       
   625             cls = __qClass(coll);
   627             cls = __qClass(coll);
   626             if (cls == @global(String) || cls == @global(ImmutableString) || cls == @global(Symbol)) {
   628             if (cls == @global(String) || cls == @global(ImmutableString) || cls == @global(Symbol)) {
   627                 if (pos < __stringSize(coll)) {
   629                 if (pos < __stringSize(coll)) {
   628                     ch = __stringVal(coll)[pos];
   630                     ch = __stringVal(coll)[pos];
   629                     RETURN ( __MKCHARACTER(ch) );
   631                     RETURN ( __MKCHARACTER(ch) );
   640                 }
   642                 }
   641             } else if (cls == @global(Array)) {
   643             } else if (cls == @global(Array)) {
   642                 if (pos < __arraySize(coll)) {
   644                 if (pos < __arraySize(coll)) {
   643                     RETURN ( __ArrayInstPtr(coll)->a_element[pos]);
   645                     RETURN ( __ArrayInstPtr(coll)->a_element[pos]);
   644                 }
   646                 }
       
   647             } else if (cls == @global(Unicode32String)) {
       
   648                 if (pos < __unicode32StringSize(coll)) {
       
   649                     ch = __unicode32StringVal(coll)[pos];
       
   650                     RETURN(__MKUCHARACTER(ch));
       
   651                 }
   645             }
   652             }
   646         }
   653         }
   647     }
   654     }
   648 %}.
   655 %}.
   649     (position >= readLimit) ifTrue:[^ self pastEndRead].
   656     (position >= readLimit) ifTrue:[^ self pastEndRead].
   650     ^ collection at:(position + 1)
   657     ^ collection at:(position + 1)
       
   658 
       
   659     "Modified: / 27-03-2019 / 15:39:55 / Claus Gittinger"
   651 !
   660 !
   652 
   661 
   653 peekOrNil
   662 peekOrNil
   654     "return the next element; do NOT advance read pointer.
   663     "return the next element; do NOT advance read pointer.
   655      return nil, if there is no next element.
   664      return nil, if there is no next element.
   693             } else if (cls == @global(Array)) {
   702             } else if (cls == @global(Array)) {
   694                 if (pos < __arraySize(coll)) {
   703                 if (pos < __arraySize(coll)) {
   695                     RETURN ( __ArrayInstPtr(coll)->a_element[pos]);
   704                     RETURN ( __ArrayInstPtr(coll)->a_element[pos]);
   696                 }
   705                 }
   697                 RETURN ( nil );
   706                 RETURN ( nil );
       
   707             } else if (cls == @global(Unicode32String)) {
       
   708                 if (pos < __unicode32StringSize(coll)) {
       
   709                     ch = __unicode32StringVal(coll)[pos];
       
   710                     RETURN(__MKUCHARACTER(ch));
       
   711                 }
       
   712                 RETURN ( nil );
   698             }
   713             }
   699         }
   714         }
   700     }
   715     }
   701 %}.
   716 %}.
   702     (position >= readLimit) ifTrue:[^ nil].
   717     (position >= readLimit) ifTrue:[^ nil].
   703     ^ collection at:(position + 1)
   718     ^ collection at:(position + 1)
       
   719 
       
   720     "Modified: / 27-03-2019 / 15:40:18 / Claus Gittinger"
   704 !
   721 !
   705 
   722 
   706 skipSeparators
   723 skipSeparators
   707     "skip all whitespace; next will return next non-white-space element.
   724     "skip all whitespace; next will return next non-white-space element.
   708      Return the peeked character or nil, if the end-of-stream was reached.
   725      Return the peeked character or nil, if the end-of-stream was reached.