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
constexpr CsvReader () noexcept
 Instantiates the object with default parameters (default constructor).
 
 ~CsvReader () noexcept
 Destructor.
 
Initialization and Finalization
errno_t Init () noexcept
 Initializes CsvReader. More...
 
errno_t Open (InputStream *stream) noexcept
 Sets an input stream. 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 nlib_utf8_t *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
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 33 of file CsvReader.h.

Member Function Documentation

◆ 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
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 50 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]streamPointer to the input stream.
Returns
Returns 0 if successful.

◆ Read() [1/2]

nn::nlib::msgpack::CsvReader::Read ( MpObject obj,
const nlib_utf8_t 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.

◆ Read() [2/2]

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: