Quotes

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:

auto f = new File ("my.csv");
auto l = new Lines (f);
auto b = new Array (0);
auto q = new Quotes(",", b);

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

See Iterator, Lines, Patterns, Delimiters.

Constructors

this
this(cstring delim, InputStream stream)

This splits on delimiters only. If there is a quote, it suspends delimiter splitting until the quote is finished.

Members

Functions

scan
size_t scan(const(void)[] data)

This splits on delimiters only. If there is a quote, it suspends delimiter splitting until the quote is finished.

Inherited Members

From Iterator

slice
cstring slice;
delim
cstring delim;
Undocumented in source.
scan
size_t scan(const(void)[] data)

The pattern scanner, implemented via subclasses.

set
Iterator set(InputStream stream)

Set the provided stream as the scanning source.

get
cstring get()

Return the current token as a slice of the content.

opApply
int opApply(int delegate(ref cstring) dg)

Iterate over the set of tokens. This should really provide read-only access to the tokens, but D does not support that at this time.

opApply
int opApply(int delegate(ref int, ref cstring) dg)

Iterate over a set of tokens, exposing a token count starting at zero.

opApply
int opApply(int delegate(ref int, ref cstring, ref cstring) dg)

Iterate over a set of tokens and delimiters, exposing a token count starting at zero.

next
cstring next()

Locate the next token. Returns the token if found, null otherwise. Null indicates an end of stream condition. To sweep a conduit for lines using method next():

set
size_t set(const(char)* content, size_t start, size_t end)

Set the content of the current slice to the provided start and end points.

set
size_t set(const(char)* content, size_t start, size_t end, size_t next)

Set the content of the current slice to the provided start and end points, and delimiter to the segment between end & next (inclusive.)

notFound
size_t notFound()

Called when a scanner fails to find a matching pattern. This may cause more content to be loaded, and a rescan initiated.

found
size_t found(size_t i)

Invoked when a scanner matches a pattern. The provided value should be the index of the last element of the matching pattern, which is converted back to a void[] index.

has
bool has(cstring set, char match)

See if set of characters holds a particular instance.

Meta