CSV parser. Reads and parses the CSV string from the stream.
More...
#include "nn/nlib/msgpack/CsvReader.h"
|
static bool | Read (MpObject *obj, const char *csvtext) noexcept |
| Parses a CSV string and stores it in an object. More...
|
|
CSV parser. Reads and parses the CSV string from the stream.
- Description
- Basically complies with RFC 4180.
- However, it is different in the following ways.
-
Both CR and LF alone, in addition to CRLF, are recognized as new line codes.
-
UTF-8 strings are passed. UTF-8 strings are checked for UTF-8 validity.
- The read data is converted to
MpObject
. The data takes the form of an array of arrays, and the length is normalized to the longest item. The field string may be converted to a different type when parsing.
- Specifics are shown below.
-
Integer and floating point values are converted to numerical values. Hex expressions are read as a string.
-
true
and false
are converted to a boolean value.
-
Empty strings are converted to
nil
.
- See also
- https://www.ietf.org/rfc/rfc4180.txt (RFC4180, CSV)
-
http://www.kasai.fm/wiki/rfc4180jp (RFC4180, CSV, in Japanese)
Definition at line 17 of file CsvReader.h.
§ Close()
nn::nlib::msgpack::CsvReader::Close |
( |
| ) |
|
|
noexcept |
Closes CsvReader
.
- Returns
- Returns
true
when successful.
- Description
- Closes
CsvReader
and detaches the base stream. The base stream will not be closed.
- The object may be reused by calling the
Init
member function again.
§ GetErrorValue()
nn::nlib::msgpack::CsvReader::GetErrorValue |
( |
| ) |
const |
|
inlinenoexcept |
Gets the error that occurred.
- Return values
-
0 | No error occurred. |
EILSEQ | Incorrect CSV character found (parse error). |
EINVAL | Error in an argument. |
EEXIST | Attempted to initialize a CsvReader that has already been initialized. |
EIO | An error occurred in the base stream. |
EBADF | Attempted to use an uninitialized CsvReader . |
ENOMEM | Failed to allocate memory. |
Definition at line 28 of file CsvReader.h.
§ GetStream()
nn::nlib::msgpack::CsvReader::GetStream |
( |
| ) |
|
|
noexcept |
Gets the base stream specified in Init
.
- Returns
- Returns the pointer to the stream.
§ Init()
nn::nlib::msgpack::CsvReader::Init |
( |
| ) |
|
|
noexcept |
Initializes CsvReader
.
- Returns
- Returns
0
if successful.
§ Open()
nn::nlib::msgpack::CsvReader::Open |
( |
InputStream * |
stream | ) |
|
|
noexcept |
Sets an input stream.
- Parameters
-
[in] | stream | Pointer to the input stream. |
- Returns
- Returns
0
if successful.
§ Read() [1/2]
nn::nlib::msgpack::CsvReader::Read |
( |
MpObject * |
obj, |
|
|
const char * |
csvtext |
|
) |
| |
|
staticnoexcept |
Parses a CSV string and stores it in an object.
- Parameters
-
[in] | obj | Object used to store the converted CSV. |
[in] | csvtext | CSV string. |
- Returns
- Returns
true
on success.
- Description
- Internally creates
CsvReader
to read and parse the CSV string from the stream. Returns false
if there is any error during this process. If this occurs, obj is not altered.
§ Read() [2/2]
nn::nlib::msgpack::CsvReader::Read |
( |
MpObject * |
obj | ) |
|
|
noexcept |
- Parameters
-
[in] | obj | Object where the CSV is stored after being read. |
- Returns
- Returns
true
when successful. Reads and parses the CSV string from the stream, and stores it in the obj parameter.
- Description
- The CSV string is converted to
MpObject
and stored in the obj parameter. Sets an error and returns false
when an error occurs while reading.
The documentation for this class was generated from the following files: