nlib
nn::nlib::msgpack::CsvReader Class Referencefinal

CSV parser. Reads and parses the CSV string from the stream. More...

#include "nn/nlib/msgpack/CsvReader.h"

Public Member Functions

bool Read (MpObject *obj) noexcept
 
InputStreamGetStream () noexcept
 Gets the base stream specified in Init. More...
 
Basic Member Functions
 CsvReader () noexcept
 Instantiates the object with default parameters (default constructor).
 
 ~CsvReader () noexcept
 Destructor.
 
Initialization and Finalization
bool Init (InputStream *stream) noexcept
 Initializes CsvWriter. More...
 
bool Close () noexcept
 Closes CsvReader. More...
 
Error Checking
errno_t GetErrorValue () const noexcept
 Gets the error that occurred. More...
 
 operator bool () const
 Returns true if an error has not occurred.
 

Static Public Member Functions

static bool Read (MpObject *obj, const char *csvtext) noexcept
 Parses a CSV string and stores it in an object. More...
 

Detailed Description

CSV parser. Reads and parses the CSV string from the stream.

Description
Generally follows RFC 4180 (https://www.ietf.org/rfc/rfc4180.txt).
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.

Definition at line 18 of file CsvReader.h.

Member Function Documentation

nn::nlib::msgpack::CsvReader::Close ( )
inlinenoexcept

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.

Definition at line 27 of file CsvReader.h.

nn::nlib::msgpack::CsvReader::GetErrorValue ( ) const
inlinenoexcept

Gets the error that occurred.

Return values
0No error occurred.
EILSEQIncorrect CSV character found (parse error).
EINVALError in an argument.
EEXISTAttempted to initialize a CsvReader that has already been initialized.
EIOAn error occurred in the base stream.
EBADFAttempted to use an uninitialized CsvReader.
ENOMEMFailed to allocate memory.

Definition at line 28 of file CsvReader.h.

nn::nlib::msgpack::CsvReader::GetStream ( )
inlinenoexcept

Gets the base stream specified in Init.

Returns
Returns the pointer to the stream.

Definition at line 33 of file CsvReader.h.

nn::nlib::msgpack::CsvReader::Init ( InputStream stream)
noexcept

Initializes CsvWriter.

Parameters
[in]streamPointer to the input stream.
Returns
Returns true when successful.
nn::nlib::msgpack::CsvReader::Read ( MpObject obj,
const char *  csvtext 
)
staticnoexcept

Parses a CSV string and stores it in an object.

Parameters
[in]objObject used to store the converted CSV.
[in]csvtextCSV 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.
nn::nlib::msgpack::CsvReader::Read ( MpObject obj)
noexcept
Parameters
[in]objObject 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: