With iterators, I guess one could have a basic line iterator that keeps the lineendings, and filter it like
foreach(f->line_iterator();; string x) ... /* Process full lines */
foreach(some_filter(f->line_iterator());; string x) ... /* Process filtered lines */
where some_filter could for example
* Strip line endings * Strip strip line endings as well as other trailing white space * Strip leading white space * Strip empty lines * Strip #-style comments * Process -style lines continuations
etc. I'm not very familiar with the iterator stuff, but I hope it's reasonably easy to write such filters, by stacking one iterator on top of another.
And if anybody thinks that helps readability, perhaps one could arrange the line_iterator to take the filter as an argument (but on the other hand, it might make more sense to give line_iterator an optional argument that says what kind of end-of-line characters it should recognize).
/ Niels Möller ()
Previous text:
2002-12-31 23:25: Subject: stdin->line_iterator
The problem is really that I once designed gets() to *not* return the newlines as a part of the returned string. If the newlines were returned, then it would be easy see what is going on at all times:
"a\nb" would return "a\n" and then "b"
/ Fredrik (Naranek) Hubinette (Real Build Master)