Class to read a CSV file.
More...
#include <Reader.h>
Class to read a CSV file.
This class
- See also
- See Parser for details
◆ Reader() [1/2]
Construct a CSV reader.
- Parameters
-
| source | Stream to read CSV text from, reader takes ownership |
| options | |
| headings | Required if source data does not contain field headings as first row |
◆ Reader() [2/2]
| CSV::Reader::Reader |
( |
IDataSourceStream * |
source, |
|
|
char |
fieldSeparator = ',', |
|
|
const CStringArray & |
headings = nullptr, |
|
|
uint16_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 CSV::Reader::getColumn |
( |
const char * |
name | ) |
const |
|
inline |
Get index of column given its name.
- Parameters
-
- Return values
-
| int | -1 if name is not found |
◆ getCursor()
| const Cursor& CSV::Parser::getCursor |
|
inline |
Get cursor position for current row.
◆ getHeadings()
◆ getRow()
◆ getValue() [1/2]
| const char* CSV::Reader::getValue |
( |
const char * |
name | ) |
const |
|
inline |
Get a value from the current row.
- Parameters
-
- Return values
-
| const | char* nullptr if name is not found |
◆ getValue() [2/2]
| const char* CSV::Reader::getValue |
( |
unsigned |
index | ) |
const |
|
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()
| bool CSV::Reader::next |
( |
| ) |
|
|
inline |
Seek to next record.
- Return values
-
| bool | true on success, false if there are no more records |
◆ operator bool()
| CSV::Reader::operator bool |
( |
| ) |
const |
|
inlineexplicit |
Determine if reader is valid.
◆ reset()
| void CSV::Reader::reset |
( |
| ) |
|
|
inline |
Reset reader to start of CSV file.
Cursor is set to 'before start'. Call 'next()' to fetch first record.
◆ seek() [1/2]
| bool CSV::Reader::seek |
( |
const Cursor & |
cursor | ) |
|
|
inline |
◆ seek() [2/2]
| bool CSV::Reader::seek |
( |
int |
offset | ) |
|
Set reader to previously noted position.
- Parameters
-
- Return values
-
| bool | true on success, false on failure or end of records |
- Note
- Source stream must support random seeking (seekFrom)
If cursor is BOF then there will be no current record until next() is called. This is the same as if next() were called.
Otherwise the corresponding row will be available via getRow().
◆ tell()
Get cursor position for current row.
The returned value indicates source stream offset for start of current row. After construction cursor is set to -1. This indicates 'Before first record' (BOF).
The documentation for this class was generated from the following file: