Parse Single Line Without Loading File
Closed this issue · 3 comments
wmcnamara commented
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
Hi,
there is the LineReader(const char*file_name, const char*data_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
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
vector<char>buffer;
LineReader("string used as file name in error messages", buffer.data(), buffer.data()+data.size());