GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Categories
  • Newsletter
  • Submit
  • Login
  • Awesome C++
  • CSV

This view

  • Original page
  • New address

GeezerVison is showing cpp.libhunt.com — lazycsv Alternatives - C++ CSV | LibHunt

  • Subscribe
  • Submit
  • Categories
  • About
  • Login

lazycsv

A fast, lightweight and single-header C++ csv parser library

ashtum logo
Source Code    Changelog
Suggest Changes
Take the C++ Developer Survey - About 6 minutes on the tools, libraries and AI you use with C++. You get the results by email. Take the survey »
Popularity
2.4
Growing
Activity
5.1
-
Stars 97
Watchers 4
Forks 12
Last Commit 10 months ago

Description

A fast, lightweight and single-header csv parser for modern C++

Programming language: C++
License: MIT License
Tags: Header Only     CSV     CSV Parser    

lazycsv alternatives and similar libraries

Based on the "CSV" category.
Alternatively, view lazycsv alternatives based on common mentions on social networks and blogs.

  • Fast C++ CSV Parser

    7.0 2.9 lazycsv VS Fast C++ CSV Parser
    fast-cpp-csv-parser
    ben-strasser logo
  • Vince's CSV Parser

    5.6 8.8 lazycsv VS Vince's CSV Parser
    A modern C++ CSV parser and serializer that doesn't make you choose between ease of use or performance.
    vincentlaucsb logo
  • SaaSHub - Software Alternatives and Reviews

    SaaSHub helps you find the best software and product alternatives
    Promo www.saashub.com
    SaaSHub Logo
  • Rapidcsv

    5.5 6.1 lazycsv VS Rapidcsv
    C++ CSV parser library
    d99kris logo
  • nvParse

    4.0 0.0 lazycsv VS nvParse
    Fast, gpu-based CSV parser
    antonmks logo
  • csv

    3.3 2.5 lazycsv VS csv
    DISCONTINUED. CSV for Modern C++
  • CSV Parser for C++ by TG

    0.9 8.0 lazycsv VS CSV Parser for C++ by TG
    A C++ library for parsing, reading CSV files that supports mixed data types, customizable delimiters, and efficient data manipulation. Perfect for data processing, analysis, and integration into larger C++ projects.
    TejasvaGupta05 logo

Do you think we are missing an alternative of lazycsv or a related project?

Add another 'CSV' Library

Popular Comparisons

  • lazycsv
    vs
    Fast C++ CSV Parser
  • lazycsv
    vs
    Rapidcsv
  • lazycsv
    vs
    csv
  • lazycsv
    vs
    nvParse
  • lazycsv
    vs
    Vince's CSV Parser

README

Build Status Language grade: C/C++

[lazycsv](img/logo.png)

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).

#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

Do not miss the trending, libraries, news and articles with our weekly report.

Awesome C++ is part of the LibHunt network. Terms. Privacy Policy.

(CC)
BY-SA
Spin The Wheel Of Names for a cryptographically secure random name picker.
Schedule a when to meet poll.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.