All Projects → AriaFallah → Csv Parser

AriaFallah / Csv Parser

Licence: mit
Fast, header-only, extensively tested, C++11 CSV parser

Programming Languages

cpp
1120 projects
cpp11
221 projects

Projects that are alternatives of or similar to Csv Parser

Csv Parser
A modern C++ library for reading, writing, and analyzing CSV (and similar) files.
Stars: ✭ 359 (+298.89%)
Mutual labels:  csv, parser, csv-parser
Swiftcsv
CSV parser for Swift
Stars: ✭ 511 (+467.78%)
Mutual labels:  csv, parser
Csvutil
csvutil provides fast and idiomatic mapping between CSV and Go (golang) values.
Stars: ✭ 501 (+456.67%)
Mutual labels:  csv, csv-parser
Clevercsv
CleverCSV is a Python package for handling messy CSV files. It provides a drop-in replacement for the builtin CSV module with improved dialect detection, and comes with a handy command line application for working with CSV files.
Stars: ✭ 887 (+885.56%)
Mutual labels:  csv, csv-parser
Stream Parser
⚡ PHP7 / Laravel Multi-format Streaming Parser
Stars: ✭ 391 (+334.44%)
Mutual labels:  csv, parser
Jsoncons
A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON
Stars: ✭ 400 (+344.44%)
Mutual labels:  csv, csv-parser
Filehelpers
The FileHelpers are a free and easy to use .NET library to read/write data from fixed length or delimited records in files, strings or streams
Stars: ✭ 917 (+918.89%)
Mutual labels:  csv, csv-parser
Node Csv
Full featured CSV parser with simple api and tested against large datasets.
Stars: ✭ 3,068 (+3308.89%)
Mutual labels:  csv, parser
Fast Csv
CSV parser and formatter for node
Stars: ✭ 1,054 (+1071.11%)
Mutual labels:  csv, csv-parser
Faster Than Csv
Faster CSV on Python 3
Stars: ✭ 52 (-42.22%)
Mutual labels:  csv, csv-parser
Csv
Fast C# CSV parser
Stars: ✭ 53 (-41.11%)
Mutual labels:  csv, csv-parser
Choetl
ETL Framework for .NET / c# (Parser / Writer for CSV, Flat, Xml, JSON, Key-Value, Parquet, Yaml, Avro formatted files)
Stars: ✭ 372 (+313.33%)
Mutual labels:  csv, parser
Csvparser
C++ parser for CSV file format
Stars: ✭ 65 (-27.78%)
Mutual labels:  csv, parser
Vroom
Fast reading of delimited files
Stars: ✭ 462 (+413.33%)
Mutual labels:  csv, csv-parser
Awesomecsv
🕶️A curated list of awesome tools for dealing with CSV.
Stars: ✭ 305 (+238.89%)
Mutual labels:  csv, csv-parser
Node Csv Parse
CSV parsing implementing the Node.js `stream.Transform` API
Stars: ✭ 768 (+753.33%)
Mutual labels:  csv, parser
flatpack
CSV/Tab Delimited and Fixed Length Parser and Writer
Stars: ✭ 55 (-38.89%)
Mutual labels:  csv, csv-parser
VBA-CSV-interface
The most powerful and comprehensive CSV/TSV/DSV data management library for VBA, providing parsing/writing capabilities compliant with RFC-4180 specifications and a complete set of tools for manipulating records and fields.
Stars: ✭ 24 (-73.33%)
Mutual labels:  csv, csv-parser
Ssp
C++ CSV parser
Stars: ✭ 30 (-66.67%)
Mutual labels:  csv, parser
Csv File Validator
🔧🔦 Validation of CSV file against user defined schema (returns back object with data and invalid messages)
Stars: ✭ 60 (-33.33%)
Mutual labels:  csv, csv-parser

CSV Parser

Fast, header-only, C++11 CSV parser.

Usage

Configuration

You initialize the parser by passing it any input stream of characters. For example, you can read from a file

std::ifstream f("some_file.csv");
CsvParser parser(f);

or you can read from stdin

CsvParser parser(std::cin);

Moreover, you can configure the parser by chaining configuration methods like

CsvParser parser = CsvParser(std::cin)
  .delimiter(';')    // delimited by ; instead of ,
  .quote('\'')       // quoted fields use ' instead of "
  .terminator('\0'); // terminated by \0 instead of by \r\n, \n, or \r

Parsing

You can read from the CSV using a range based for loop. Each row of the CSV is represented as a std::vector<std::string>.

#include <iostream>
#include "../parser.hpp"

using namespace aria::csv;

int main() {
  std::ifstream f("some_file.csv");
  CsvParser parser(f);

  for (auto& row : parser) {
    for (auto& field : row) {
      std::cout << field << " | ";
    }
    std::cout << std::endl;
  }
}

Behind the scenes, when using the range based for, the parser only ever allocates as much memory as needed to represent a single row of your CSV. If that's too much, you can step down to a lower level, where you read from the CSV a field at a time, which only allocates the amount of memory needed for a single field.

#include <iostream>
#include "./parser.hpp"

using namespace aria::csv;

int main() {
  CsvParser parser(std::cin);

  for (;;) {
    auto field = parser.next_field();
    switch (field.type) {
      case FieldType::DATA:
        std::cout << *field.data << " | ";
        break;
      case FieldType::ROW_END:
        std::cout << std::endl;
        break;
      case FieldType::CSV_END:
        std::cout << std::endl;
        return 0;
    }
  }
}

It is possible to inspect the current cursor position using parser.position(). This will return the position of the last parsed token. This is useful when reporting things like progress through a file. You can use file.seekg(0, std::ios::end); to get a file size.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].