C++ CSV parser
Go to file
2020-12-27 22:13:43 +01:00
include/ss add README, start writing documentation 2020-12-27 20:50:45 +01:00
test make default error_mode Bool 2020-12-27 17:00:06 +01:00
.gitignore initial commit, copy everything to new repository 2020-12-10 19:26:56 +01:00
LICENSE Initial commit 2020-12-10 18:59:46 +01:00
makefile update converter.hpp to work with gcc, add uninstall to makefile 2020-12-10 20:41:49 +01:00
README.md update README 2020-12-27 22:13:43 +01:00

Static split parser

A header only "csv" parser which is fast and versatile with modern C++ api. Requires compiler with C++17 support.

Conversion for numeric values taken from Oliver Schönrock .
Function traits taken from qt-creator .

Example

Lets say we have a csv file containing students in the following format <name,age,grade>:

$ cat students.csv
James Bailey,65,2.5
Brian S. Wolfe,40,11.9
Nathan Fielder,37,Really good grades
Bill (Heath) Gates,65,3.3
#include <iostream>
#include <ss/parser.hpp>

int main() {
    ss::parser p{"students.csv", ","};
    if (!p.valid()) {
        exit(EXIT_FAILURE);
    }

    while (!p.eof()) {
        auto [name, age, grade] = p.get_next<std::string, int, double>();

        if (p.valid()) {
            std::cout << name << ' ' << age << ' ' << grade << std::endl;
        }
    }

    return 0;
}

And if we compile and execute the program we get the following output:

$ ./a.out
James Bailey 65 2.5
Brian S. Wolfe 40 11.9
Bill (Heath) Gates 65 3.3

Features

  • Works on any type
  • No exceptions
  • Columns and rows can be ignored
  • Works with any type of delimiter
  • Can return whole objects composed of converted values
  • Descriptive error handling can be enabled
  • Restrictions can be added for each column
  • Works with std::optional and std::variant
  • Works with CRLF and LF
  • Conversions can be chained if invalid
  • Fast

Instalation

$ git clone https://github.com/red0124/ssp
$ cd ssp
$ sudo make install

Usage

...