tango.io.stream.Quotes

License:

BSD style: see license.txt

Version:

Jan 2006: initial release

Author:

Kris, Nthalk
class Quotes(T) : Iterator!(T)
Iterate over a set of delimited, optionally-quoted, text fields.
Each field is exposed to the client as a slice of the original content, where the slice is transient. If you need to retain the exposed content, then you should .dup it appropriately.

The content exposed via an iterator is supposed to be entirely read-only. All current iterators abide by this rule, but it is possible a user could mutate the content through a get() slice. To enforce the desired read-only aspect, the code would have to introduce redundant copying or the compiler would have to support read-only arrays.

Usage:

1
2
3
4
5
6
7
8
9
10
11
12
auto f = new File ("my.csv");
auto l = new Lines (f);
auto b = new Array (0);
auto q = new Quotes!(char)(",", b);

foreach (line; l)
        {
        b.assign (line);
        foreach (field, index; q)
                 Stdout (index, field);
        Stdout.newline;
        }

See Iterator, Lines, Patterns, Delimiters.
this(const(T)[] delim, InputStream stream = null)
This splits on delimiters only. If there is a quote, it suspends delimiter splitting until the quote is finished.
size_t scan(const(void)[] data) [protected, override]
This splits on delimiters only. If there is a quote, it suspends delimiter splitting until the quote is finished.