FBB::CSV4180(3bobcat)

CSV4180 convertor
(libbobcat-dev_6.02.02)

2005-2022

NAME

FBB::CSV4180 - Converter for comma separated values

SYNOPSIS

#include <bobcat/csv>

Linking option: -lbobcat

DESCRIPTION

Objects of the class CSV4180 can be used to convert series of comma separated values to the individual separated values (also called `fields' below). The class implements RFC 4180 (cf. https://www.ietf.org/rfc/rfc4180.txt, section 2).

According to RFC 4180 lines contain comma separated values: comma separated values on one line are processed together, as a series of values. The final comma separated value on a line is not ended by a comma.

Comma separated values may be surrounded by double quotes. However, they must be surrounded by double quotes in these cases:

Comma separated values may be empty: the following line defines three empty comma separated values:


,,
        
The first empty value starts at the beginning of the line, and continues up to the first comma; the second empty value starts beyond the first comma and continues up to the second comma; the third empty value starts beyond the second comma, and continues up to the end of the line. If the line ends in blank space characters then the third value isn't empty, but contains those blank space characters.

By default, values are interpreted as strings. The CSV4180 class also offers facilities to ignore specific fields, or to ensure that they can be converted to integral or floating point values. The second constructor (below) expects a std::string argument defining how to interpret fields. Options are:

In addition, field specifications may contain blank spaces, which are ignored.

When processing comma separated values the first line may be considered a header line. X specifications also apply to header lines, but otherwise they merely consist of S-type fields. In addition, when processing multiple input lines all non-header lines are made available in a vector of vectors of fields, whereas the header line itself can be accessed via a dedicated member (header()).

NAMESPACE

FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.

INHERITS FROM

-

CONSTRUCTORS

Copy and move constructors (and assignment operators) are available.

OVERLOADED OPERATORS

MEMBER FUNCTIONS

EXAMPLE

#include <iostream>

#include <bobcat/csv4180>

using namespace std;
using namespace FBB;

int main(int argc, char **argv)
{

    CSV4180 csv;                    // this processes 'input'

    size_t nLines = csv.read(cin);

    cerr << nLines << " lines were read\n";
    if (not csv.header().empty())
    {
        cerr << "header: " << '\n';
        for (auto const &field: csv.header())
            cerr << "   `" << field << "'\n";
    }

    cerr << "# CSV values: " << csv.nValues() << '\n';
    for (auto const &line: csv.data())
    {
        cerr << "Line:\n";
        for (auto const &entry: line)
            cerr << "   `" << entry << "'\n";
    }
}

FILES

bobcat/csv - defines the class interface

SEE ALSO

bobcat(7)

BUGS

None Reported.

BOBCAT PROJECT FILES

BOBCAT

Bobcat is an acronym of `Brokken's Own Base Classes And Templates'.

COPYRIGHT

This is free software, distributed under the terms of the GNU General Public License (GPL).

AUTHOR

Frank B. Brokken (f.b.brokken@rug.nl).