Loading...
Searching...
No Matches
CsvUtil::CsvIterator Class Reference

The CsvIterator class allows CSV sources to be iterated on a record basis. More...

`#include <CsvIterator.qc.dox.h>`

Inheritance diagram for CsvUtil::CsvIterator:
[legend]

## Public Member Functions

| constructor (Qore::AbstractLineIterator li, *hash< auto > opts)
| Creates the CsvIterator in single-type mode with general line iterator to read and an option hash.
| constructor (Qore::AbstractLineIterator li, hash< auto > spec, hash< auto > opts)
| Creates the CsvIterator in multi-type mode with general line iterator to read and optionally an option hash.
| constructor (Qore::InputStream input, string encoding='UTF-8', *hash< auto > opts)
| Creates the CsvIterator from an InputStream and other arguments.
| constructor (Qore::InputStream input, string encoding='UTF-8', hash< auto > spec, hash< auto > opts)
| Creates the CsvIterator in multi-type mode from an InputStream and other arguments.
Public Member Functions inherited from CsvUtil::AbstractCsvIterator
| constructor (AbstractLineIterator li, *hash< auto > opts)
| creates the AbstractCsvIterator with an option hash in single-type mode
| constructor (AbstractLineIterator li, hash< auto > spec, hash< auto > opts)
| creates the AbstractCsvIterator with an option hash in multi-type mode
*list< string > | getHeaders ()
| Returns the current record headers or NOTHING if no headers have been detected or saved yet.
*list< string > | getHeaders (string type)
| Returns a list of headers for the given record or NOTHING if the record is not recognized.
string | getQuote ()
| Returns the current quote string.
string | getRawLine ()
| Returns the current line 'as it is', i.e. the original string.
list< *string > | getRawLineValues ()
| Returns the list of raw string values of the current line.
hash< auto > | getRecord ()
| Returns the current record as a hash.
hash< auto > | getRecord (bool extended)
| Returns the current record as a hash.
auto | getRecordList ()
| Returns the current record as a list.
*hash< string, AbstractDataField > | getRecordType ()
| Returns the description of the record type, if any.
string | getSeparator ()
| Returns the current separator string.
hash< auto > | getValue ()
| Returns the current record as a hash.
string | identifyType (list< auto > rec)
| Identify a fixed-length line type using identifyTypeImpl(); may be overridden if necessary.
int | index ()
| Returns the row index being iterated, which does not necessarily correspond to the line number when there are header rows and blank lines are skipped.
int | lineNumber ()
| Returns the current iterator line number in the file (the first line is line 1) or 0 if not pointing at a valid element.
auto | memberGate (string name)
| Returns the given column value for the current row.
bool | next ()
| Moves the current line / record position to the next line / record; returns False if there are no more lines to iterate.
| peek ()
| Reads a single row without moving the index position.

## Additional Inherited Members

Protected Member Functions inherited from CsvUtil::AbstractCsvIterator
list< *string > | getLineAndSplit ()
| Read line split by separator/quote into list.
*string | identifyTypeImpl (list< auto > rec)

Identify a input record, given the raw line string. This method performs a lookup to a precalculated table based on number of records (see constructor()). In case different criteria are needed, eg. when two line types in a spec have the same record number and no unique resolving rule are specified, this method needs to be overridden, otherwise it will throw an exception because the precalculated mapping will be empty.

hash< auto > | parseLine ()
| Parses a line in the file and returns a processed list of the fields.
| prepareFieldsFromHeaders (*list< auto > headers)
| match headers provided at csv header or in options, never called for multi-type because header_names is False
| processCommonOptions (*hash< auto > opts, int C_OPTx)
| process common options and and assing internal fields
| processSpec (hash< auto > spec)
| process specification and assing internal data for resolving
Protected Attributes inherited from CsvUtil::AbstractCsvIterator
*string | eol
| the eol marker, if any
const | Options
| valid options for the object (a hash for quick lookups of valid keys)

## Detailed Description

The CsvIterator class allows CSV sources to be iterated on a record basis.

The source of the input data is either a AbstractLineIterator object or an InputStream object.

See also
  - AbstractCsvIterator Constructor Option Hash Overview
  - Option Field Types
  - Option Field Hash

## Member Function Documentation

## constructor() [1/4]

CsvUtil::CsvIterator::constructor | ( | Qore::AbstractLineIterator | li,
|  | *hash< auto > | opts
| ) |  |

Creates the CsvIterator in single-type mode with general line iterator to read and an option hash.

Parameters

  li | line iterator of CSV file to read
  opts | a hash of optional options; see AbstractCsvIterator Constructor Option Hash Overview for more information

Exceptions

  ABSTRACTCSVITERATOR-ERROR | invalid or unknown option; invalid data type for option; `"header_names"` is True and `"header_lines"` is 0 or `"headers"` is also present; unknown field type

## constructor() [2/4]

CsvUtil::CsvIterator::constructor | ( | Qore::AbstractLineIterator | li,
|  | hash< auto > | spec,
|  | hash< auto > | opts
| ) |  |

Creates the CsvIterator in multi-type mode with general line iterator to read and optionally an option hash.

Parameters

  li | line iterator of CSV file to read
  spec | a hash of field and type definition; see Option Field Hash for more information
  opts | a hash of optional options; see AbstractCsvIterator Constructor Option Hash Overview for more information

Exceptions

  ABSTRACTCSVITERATOR-ERROR | invalid or unknown option; invalid data type for option; `"header_names"` is True and `"header_lines"` is 0 or `"headers"` is also present; unknown field type

## constructor() [3/4]

CsvUtil::CsvIterator::constructor | ( | Qore::InputStream | input,
|  | string | encoding = `'UTF-8'`,
|  | *hash< auto > | opts
| ) |  |

Creates the CsvIterator from an InputStream and other arguments.

Parameters

  input | the InputStream providing data to iterate
  encoding | the encoding of the input stream
  opts | a hash of optional options; see AbstractCsvIterator Constructor Option Hash Overview for more information

Exceptions

  ABSTRACTCSVITERATOR-ERROR | invalid or unknown option; invalid data type for option; `"header_names"` is True and `"header_lines"` is 0 or `"headers"` is also present; unknown field type

## constructor() [4/4]

CsvUtil::CsvIterator::constructor | ( | Qore::InputStream | input,
|  | string | encoding = `'UTF-8'`,
|  | hash< auto > | spec,
|  | hash< auto > | opts
| ) |  |

Creates the CsvIterator in multi-type mode from an InputStream and other arguments.

Parameters

  input | the InputStream providing data to iterate
  encoding | the encoding of the input stream
  spec | a hash of field and type definition; see Option Field Hash for more information
  opts | a hash of optional options; see AbstractCsvIterator Constructor Option Hash Overview for more information

Exceptions

  ABSTRACTCSVITERATOR-ERROR | invalid or unknown option; invalid data type for option; `"header_names"` is True and `"header_lines"` is 0 or `"headers"` is also present; unknown field type