PartialCsvParser  0.1.2
 All Classes Namespaces Files Functions Variables Typedefs Macros Pages
Public Member Functions | List of all members
PCP::PartialCsvParser Class Reference

Parser to split CSV into rows and columns. More...

#include <PartialCsvParser.hpp>

Public Member Functions

 PartialCsvParser (const Memory::CsvConfig &csv_config, size_t parse_from=PARSE_FROM_BODY_BEGINNING, size_t parse_to=PARSE_TO_FILE_END)
 Constructor. More...
 
 ~PartialCsvParser ()
 
std::vector< std::string > get_row () throw (PCPCsvError)
 Returns an array of parsed columns. More...
 

Detailed Description

Parser to split CSV into rows and columns.

Constructor & Destructor Documentation

PCP::PartialCsvParser::PartialCsvParser ( const Memory::CsvConfig csv_config,
size_t  parse_from = PARSE_FROM_BODY_BEGINNING,
size_t  parse_to = PARSE_TO_FILE_END 
)
inline

Constructor.

Parameters
csv_configInstance of Memory::CsvConfig or its child class.
parse_fromCSV file's approximate offset to start parsing. Must be no less than CsvConfig::body_offset(). parse_from = PARSE_FROM_BODY_BEGINNING has the same meaning with parse_from = CsvConfig::body_offset().
parse_toCSV file's approximate offset to stop parsing. Must be no less than parse_from and less than CsvConfig::filesize(). parse_to = PARSE_TO_FILE_END has the same meaning with parse_to = CsvConfig::filesize() - 1.

In order to fully parse CSV lines without overlaps, parse_from and parse_to are interpreted with the following strategy.

<----—> means range from parse_from to parse_to.

(beginning of CSV)  aaaaaaaaaaaaaaaa \0
                    <---><-----><-->
                     (1)   (2)   (3)

In this severe edge case, only (1), who covers the beginning of line, parses line "aaaaaaaaaaaaaaaa" to prevent overlap.

(beginning of CSV)  aaaaaaaaaaaaa \n bbbbbbbbbbb \0
                    <---><-------->  <--------->
                     (1)    (2)          (3)

In this case, (1) parses "aaaaaaaaaaaaa", (2) parses no line, and (3) parses "bbbbbbbbbbb".

(beginning of CSV)  aaaaaaaaaaaaa \n bbbbbbbbbbb \0
                    <---><-----------><-------->
                     (1)      (2)         (3)

In this case, (1) parses "aaaaaaaaaaaaa", (2) parses "bbbbbbbbbbb", and (3) parses no line.

In short, partial parser who covers the beginning of a line parses the line.

PCP::PartialCsvParser::~PartialCsvParser ( )
inline

Member Function Documentation

std::vector<std::string> PCP::PartialCsvParser::get_row ( )
throw (PCPCsvError
)
inline

Returns an array of parsed columns.

Parses only around [parse_from, parse_to) specified in constructor is parsed.

Returns
Array of columns if line to parse remains. Otherwise, empty vector is returned. Check by retval.empty().

The documentation for this class was generated from the following file: