ben-strasser / fast-cpp-csv-parser

fast-cpp-csv-parser
BSD 3-Clause "New" or "Revised" License
2.09k stars 435 forks source link

Parse Single Line Without Loading File #121

Closed wmcnamara closed 2 years ago

wmcnamara commented 3 years ago

Is there a way to parse just a single std::string row without loading a file?

It looks like the linereader class constructors all want filepaths, but I have a std::string with the row that I need to parse. Does this library provide a way to parse this?

Example:

std::string csvRowText = aRowFromCSVFile;
LineReader(csvRowTest);
//get the data points from that row below
ben-strasser commented 3 years ago

Hi,

there is the LineReader(const charfile_name, const chardata_begin, const char*data_end) constructor, which parses an in-memory file. For anything more complex, you can derive from ByteSourceBase and implement your byte reading logic there.

You cannot parse lines interactively, as the reader has a large internal buffer and fills this buffer before doing any parsing.

wmcnamara commented 3 years ago

Ok, I see.

Can you provide a small example on using this LineReader constructor to read CSV data similar to my usecase if its no trouble? I'm just a bit confused on how to actually get it up and running

ben-strasser commented 2 years ago
vector<char>buffer;
LineReader("string used as file name in error messages", buffer.data(), buffer.data()+data.size());