ocean.text.csv.HeadingsCSV

Class for parsing streams of CSV data with handling of column headings. The fields of the first row are parsed as the column headings. The user delegate passed to the parse() methods receives the values of the fields in a row together with the corresponding column headings, read from the first row.

A second parse() method allows only certain columns in the CSV stream to be processed.

See ocean.text.csv.CSV for details on the basic format support of the parser.

Usage:

import ocean.io.Stdout;
import ocean.io.device.File;

scope file = new File("example.csv", File.ReadExisting);
scope csv = new HeadingsCSV;

const include_headings = ["Criteria ID", "Country Code", "Canonical Name"];

// Parse method allowing only certain columns to be passed to the
// delegate.
csv.parse(file, include_headings,
(HeadingsCSV.Field[] fields)
{
    Stdout.format("Row=[");
    foreach ( f; fields )
    {
        Stdout.format("{}:{}, ", f.name, f.value);
    }
    Stdout.formatln("]");
    return true; // tells CSV instance to continue parsing
});

Members

Classes

HeadingsCSV
class HeadingsCSV

CSV parser with special handling of column headings. Passes extracted fields, one row at a time to a user-provided delegate, along with the column heading of each field.

Meta

License

Boost Software License Version 1.0. See LICENSE_BOOST.txt for details. Alternatively, this file may be distributed under the terms of the Tango 3-Clause BSD License (see LICENSE_BSD.txt for details).