All Projects → ashtum → lazycsv

ashtum / lazycsv

Licence: MIT license
A fast, lightweight and single-header c++ csv parser library

Programming Languages

C++
36643 projects - #6 most used programming language

Projects that are alternatives of or similar to lazycsv

Cursively
A CSV reader for .NET. Fast, RFC 4180 compliant, and fault tolerant. UTF-8 only.
Stars: ✭ 34 (-35.85%)
Mutual labels:  csv-parser, csv-reader
java-read-write-csv-file
Read and Write CSV files in Java using Apache Commons CSV and OpenCSV
Stars: ✭ 57 (+7.55%)
Mutual labels:  csv-parser, csv-reader
CsvTextFieldParser
A simple CSV parser based on Microsoft.VisualBasic.FileIO.TextFieldParser.
Stars: ✭ 40 (-24.53%)
Mutual labels:  csv-parser, csv-reader
Windmill
A library to parse or write Excel and CSV files through a fluent API
Stars: ✭ 19 (-64.15%)
Mutual labels:  csv-parser, csv-reader
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 (-54.72%)
Mutual labels:  csv-parser, csv-reader
Csv Stream
📃 Streaming CSV Parser for Node. Small and made entirely out of streams.
Stars: ✭ 98 (+84.91%)
Mutual labels:  csv-parser
Intellij Csv Validator
CSV validator, highlighter and formatter plugin for JetBrains Intellij IDEA, PyCharm, WebStorm, ...
Stars: ✭ 198 (+273.58%)
Mutual labels:  csv-parser
Ngx Papaparse
Papa Parse wrapper for Angular
Stars: ✭ 83 (+56.6%)
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 (+13.21%)
Mutual labels:  csv-parser
csv-localizer
Command Line Interface that convert CSV file to iOS, Android or JSON localizable strings
Stars: ✭ 84 (+58.49%)
Mutual labels:  csv-parser
Csv2
Fast CSV parser and writer for Modern C++
Stars: ✭ 164 (+209.43%)
Mutual labels:  csv-parser
Papaparse
Fast and powerful CSV (delimited text) parser that gracefully handles large files and malformed input
Stars: ✭ 10,206 (+19156.6%)
Mutual labels:  csv-parser
Codablecsv
Read and write CSV files row-by-row or through Swift's Codable interface.
Stars: ✭ 214 (+303.77%)
Mutual labels:  csv-parser
Csv Parser
Fast, header-only, extensively tested, C++11 CSV parser
Stars: ✭ 90 (+69.81%)
Mutual labels:  csv-parser
React Csv Reader
React component that handles csv file input and its parsing
Stars: ✭ 138 (+160.38%)
Mutual labels:  csv-parser
Csvparser
A swift package for read and write CSV file
Stars: ✭ 73 (+37.74%)
Mutual labels:  csv-parser
Tinycsvparser
Easy to use, easy to extend and high-performance library for CSV parsing with .NET
Stars: ✭ 247 (+366.04%)
Mutual labels:  csv-parser
Dataclass Csv
Map CSV to Data Classes
Stars: ✭ 133 (+150.94%)
Mutual labels:  csv-parser
Etl.net
Mass processing data with a complete ETL for .net developers
Stars: ✭ 129 (+143.4%)
Mutual labels:  csv-parser
Cassava
A CSV parsing and encoding library optimized for ease of use and high performance
Stars: ✭ 193 (+264.15%)
Mutual labels:  csv-parser

Build Status Language grade: C/C++

lazycsv

What's the lazycsv?

lazycsv is a c++17, posix-compliant, single-header library for reading and parsing csv files.
It's fast and lightweight and does not allocate any memory in the constructor or while parsing. It parses each row and cell just on demand on each iteration, that's why it's called lazy.

Note

This parser does not handle quoted cells yet.

Quick usage

The latest version of the single header can be downloaded from include/lazycsv.hpp.

#include <lazycsv.hpp>

int main()
{
    lazycsv::parser parser{ "contacts.csv" };
    for (const auto row : parser)
    {
        const auto [id, name, phone] = row.cells(0, 1, 4); // indexes must be in ascending order
    }
}

Performance note

Parser doesn't keep state of already parsed rows and cells, iterating through them always associated with parsing cost. This is true with cells() member function too, geting all needed cells by a single call is recommended.
If it's necessary to return to the already parsed rows and cells, they can be stored in a container and used later without being parsed again (they are view objects and efficient to copy).

Features

Returned std::string_view by raw() and trimed() member functions are valid as long as the parser object is alive:

std::vector<std::string_view> cities;
for (const auto row : parser)
{
    const auto [city, state] = row.cells(0, 1);
    cities.push_back(city.trimed());
}

Iterate through rows and cells:

for (const auto row : parser)
{
    for (const auto cell : row)
    {
    }
}

Get header row and iterate through its cells:

auto header = parser.header();
for (const auto cell : header)
{
}

Find column index by its name:

auto city_index = parser.index_of("city");

row and cell are view objects on actual data in the parser object, they can be stored and used as long as the parser object is alive:

std::vector<lazycsv::parser<>::row> desired_rows;
std::vector<lazycsv::parser<>::cell> desired_cells;
for (const auto row : parser)
{
    const auto [city] = row.cells(6);
    desired_cells.push_back(city);

    if (city.trimed() == "Kashan")
        desired_rows.push_back(row);
}
static_assert(sizeof(lazycsv::parser<>::row) == 2 * sizeof(void*));  // i'm lightweight
static_assert(sizeof(lazycsv::parser<>::cell) == 2 * sizeof(void*)); // i'm lightweight too

Parser is customizable with the template parameters:

lazycsv::parser<
    lazycsv::mmap_source,           /* source type of csv data */
    lazycsv::has_header<true>,      /* first row is header or not */
    lazycsv::delimiter<','>,        /* column delimiter */
    lazycsv::trim_chars<' ', '\t'>> /* trim characters of cells */
    my_parser{ "data.csv" };

By default parser uses lazycsv::mmap_source as its source of data, but it's possible to be used with any other types of contiguous containers:

std::string csv_data{ "name,lastname,age\nPeter,Griffin,45\nchris,Griffin,14\n" };

lazycsv::parser<std::string_view> parser_a{ csv_data };
lazycsv::parser<std::string> parser_b{ csv_data };

TODO

  • Add benchmarks
  • Add parser for integral and floating point cells
  • Add policy for quoting
  • Wrapping it for python
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].