Class to parse a CSV file.
More...
#include <CsvReader.h>
Class to parse a CSV file.
Spec: https://www.ietf.org/rfc/rfc4180.txt
- Each record is located on a separate line
- Line ending for last record in the file is optional
- Field headings are provided either in the source data or in constructor (but not both)
- Fields separated with ',' and whitespace considered part of field content
- Fields may or may not be quoted - if present, will be removed during parsing
- Fields may contain line breaks, quotes or commas
- Quotes may be escaped thus "" if field itself is quoted
Additional features:
- Line breaks can be
or \r
- Escapes codes within fields will be converted:
\r \t ", \
- Field separator can be changed in constructor
◆ CsvReader()
CsvReader::CsvReader |
( |
IDataSourceStream * |
source, |
|
|
char |
fieldSeparator = ',' , |
|
|
const CStringArray & |
headings = nullptr , |
|
|
size_t |
maxLineLength = 2048 |
|
) |
| |
|
inline |
Construct a CSV reader.
- Parameters
-
source | Stream to read CSV text from |
fieldSeparator | |
headings | Required if source data does not contain field headings as first row |
maxLineLength | Limit size of buffer to guard against malformed data |
◆ count()
◆ getColumn()
int CsvReader::getColumn |
( |
const char * |
name | ) |
|
|
inline |
Get index of column given its name.
- Parameters
-
- Return values
-
int | -1 if name is not found |
◆ getHeadings()
◆ getRow()
◆ getValue() [1/2]
const char* CsvReader::getValue |
( |
const char * |
name | ) |
|
|
inline |
Get a value from the current row.
- Parameters
-
- Return values
-
const | char* nullptr if name is not found |
◆ getValue() [2/2]
const char* CsvReader::getValue |
( |
unsigned |
index | ) |
|
|
inline |
Get a value from the current row.
- Parameters
-
index | Column index, starts at 0 |
- Return values
-
const | char* nullptr if index is not valid |
◆ next()
◆ operator bool()
CsvReader::operator bool |
( |
| ) |
const |
|
inlineexplicit |
Determine if row is valid.
◆ reset()
void CsvReader::reset |
( |
| ) |
|
Reset reader to start of CSV file.
Cursor is set to 'before start'. Call 'next()' to fetch first record.
The documentation for this class was generated from the following file: