{"id":21843571,"url":"https://github.com/ariafallah/csv-parser","last_synced_at":"2025-04-04T21:07:12.555Z","repository":{"id":40658326,"uuid":"79754013","full_name":"AriaFallah/csv-parser","owner":"AriaFallah","description":"Fast, header-only, extensively tested, C++11 CSV parser","archived":false,"fork":false,"pushed_at":"2024-10-28T04:51:12.000Z","size":1023,"stargazers_count":141,"open_issues_count":4,"forks_count":29,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-28T20:07:53.418Z","etag":null,"topics":["cpp","cpp11","csv","csv-parser","parser"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AriaFallah.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-22T23:42:50.000Z","updated_at":"2025-03-13T15:21:54.000Z","dependencies_parsed_at":"2025-02-12T12:10:30.868Z","dependency_job_id":"3d087c3d-529c-41c2-bd4f-437ee1c93d96","html_url":"https://github.com/AriaFallah/csv-parser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AriaFallah%2Fcsv-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AriaFallah%2Fcsv-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AriaFallah%2Fcsv-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AriaFallah%2Fcsv-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AriaFallah","download_url":"https://codeload.github.com/AriaFallah/csv-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247249524,"owners_count":20908212,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","cpp11","csv","csv-parser","parser"],"created_at":"2024-11-27T22:15:49.344Z","updated_at":"2025-04-04T21:07:12.536Z","avatar_url":"https://github.com/AriaFallah.png","language":"C++","readme":"# CSV Parser\n\nFast, simple, header-only, C++11 CSV parser.\n\n## Usage\n\n#### Configuration\n\nYou initialize the parser by passing it any input stream of characters. For\nexample, you can read from a file\n\n```cpp\nstd::ifstream f(\"some_file.csv\");\nCsvParser parser(f);\n```\n\nor you can read from `stdin`\n\n```cpp\nCsvParser parser(std::cin);\n```\n\nMoreover, you can configure the parser by chaining configuration methods like\n\n```cpp\nCsvParser parser = CsvParser(std::cin)\n  .delimiter(';')    // delimited by ; instead of ,\n  .quote('\\'')       // quoted fields use ' instead of \"\n  .terminator('\\0'); // terminated by \\0 instead of by \\r\\n, \\n, or \\r\n```\n\n#### Parsing\n\nYou can read from the CSV using a range based for loop. Each row of the CSV is\nrepresented as a `std::vector\u003cstd::string\u003e`.\n\n```cpp\n#include \u003ciostream\u003e\n#include \"../parser.hpp\"\n\nusing namespace aria::csv;\n\nint main() {\n  std::ifstream f(\"some_file.csv\");\n  CsvParser parser(f);\n\n  for (auto\u0026 row : parser) {\n    for (auto\u0026 field : row) {\n      std::cout \u003c\u003c field \u003c\u003c \" | \";\n    }\n    std::cout \u003c\u003c std::endl;\n  }\n}\n```\n\nBehind the scenes, when using the range based for, the parser only ever\nallocates as much memory as needed to represent a single row of your CSV. If\nthat's too much, you can step down to a lower level, where you read from the CSV\na field at a time, which only allocates the amount of memory needed for a single\nfield.\n\n```cpp\n#include \u003ciostream\u003e\n#include \"./parser.hpp\"\n\nusing namespace aria::csv;\n\nint main() {\n  CsvParser parser(std::cin);\n\n  for (;;) {\n    auto field = parser.next_field();\n    switch (field.type) {\n      case FieldType::DATA:\n        std::cout \u003c\u003c *field.data \u003c\u003c \" | \";\n        break;\n      case FieldType::ROW_END:\n        std::cout \u003c\u003c std::endl;\n        break;\n      case FieldType::CSV_END:\n        std::cout \u003c\u003c std::endl;\n        return 0;\n    }\n  }\n}\n```\n\nIt is possible to inspect the current cursor position using `parser.position()`.\nThis will return the position of the last parsed token. This is useful when\nreporting things like progress through a file. You can use\n`file.seekg(0, std::ios::end);` to get a file size.\n\n## Testing\n\nRun `cmake -B out \u0026\u0026 cmake --build out \u0026\u0026 ./out/parser_test` in test dir\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fariafallah%2Fcsv-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fariafallah%2Fcsv-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fariafallah%2Fcsv-parser/lists"}