Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 3385

Show
Ignore:
Timestamp:
03/21/08 02:12:09 (6 months ago)
Author:
kris
Message:

fixes #970 :: foreach (index, line, delim; stream)

Thanks, Daniel919

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/text/stream/LineIterator.d

    r2847 r3385  
    107107                            if (i && content[i-1] is '\r') 
    108108                                --slice; 
    109                             set (content.ptr, 0, slice); 
     109                            set (content.ptr, 0, slice, i); 
    110110                            return found (i); 
    111111                            } 
     
    115115} 
    116116 
     117 
     118 
     119/******************************************************************************* 
     120 
     121*******************************************************************************/ 
     122 
     123debug (LineIterator) 
     124{ 
     125        import tango.io.Buffer; 
     126        import tango.io.Console; 
     127 
     128        void main() 
     129        { 
     130                auto lines = new LineIterator!(char)(new Buffer("one\ntwo\r\nthree")); 
     131                foreach (i, line, delim; lines) 
     132                         Cout (line) (delim); 
     133        } 
     134} 
  • trunk/tango/text/stream/QuoteIterator.d

    r2809 r3385  
    103103                foreach (int i, T c; content) 
    104104                         if (has (delim, c)) 
    105                              return found (set (content.ptr, 0, i)); 
     105                             return found (set (content.ptr, 0, i, i)); 
    106106                         else 
    107107                            if (c is '"' || c is '\'') 
  • trunk/tango/text/stream/SimpleIterator.d

    r2809 r3385  
    9191                   foreach (int i, T c; content) 
    9292                            if (c is delim[0]) 
    93                                 return found (set (content.ptr, 0, i)); 
     93                                return found (set (content.ptr, 0, i, i)); 
    9494                   } 
    9595                else 
    9696                   foreach (int i, T c; content) 
    9797                            if (has (delim, c)) 
    98                                 return found (set (content.ptr, 0, i)); 
     98                                return found (set (content.ptr, 0, i, i)); 
    9999 
    100100                return notFound; 
  • trunk/tango/text/stream/StreamIterator.d

    r3384 r3385  
    5555class StreamIterator(T) : InputStream, Buffered 
    5656{ 
    57         protected T[]           slice; 
     57        protected T[]           slice, 
     58                                delim; 
    5859        private IBuffer         input; 
    5960 
     
    157158        } 
    158159 
     160        /********************************************************************** 
     161 
     162                Iterate over a set of tokens and delimiters, exposing a  
     163                token count starting at zero 
     164 
     165        **********************************************************************/ 
     166 
     167        int opApply (int delegate(inout int, inout T[], inout T[]) dg) 
     168        { 
     169                bool more; 
     170                int  result, 
     171                     tokens; 
     172 
     173                do { 
     174                   delim = null; 
     175                   more = consume; 
     176                   result = dg (tokens, slice, delim); 
     177                   ++tokens; 
     178                   } while (more && !result); 
     179                return result; 
     180        } 
     181 
    159182        /*********************************************************************** 
    160183 
     
    180203                         Cout(line).newline; 
    181204                --- 
    182  
    183                 Note that tokens exposed via push() are returned immediately 
    184                 when available, taking priority over the input stream itself 
    185205                 
    186206        ***********************************************************************/ 
     
    195215        /*********************************************************************** 
    196216 
    197                 Set the content of the current slice 
     217                Set the content of the current slice to the provided  
     218                start and end points 
    198219 
    199220        ***********************************************************************/ 
     
    202223        { 
    203224                slice = content [start .. end]; 
     225                return end; 
     226        } 
     227 
     228        /*********************************************************************** 
     229 
     230                Set the content of the current slice to the provided  
     231                start and end points, and delimiter to the segment 
     232                between end & next (inclusive) 
     233 
     234        ***********************************************************************/ 
     235 
     236        protected final uint set (T* content, uint start, uint end, uint next) 
     237        { 
     238                slice = content [start .. end]; 
     239                delim = content [end .. next+1]; 
    204240                return end; 
    205241        }