Qore FixedLengthUtil Module Reference  1.1
FixedLengthUtil::FixedLengthIterator Class Reference

The FixedLengthIterator class allows CSV sources to be iterated on a record basis. The source of the input data is an AbstractLineIterator object or an InputStream. More...

Inheritance diagram for FixedLengthUtil::FixedLengthIterator:

Public Member Methods

 constructor (Qore::AbstractLineIterator li, hash spec, *hash opts)
 Creates the FixedLengthIterator in single-type mode with general line iterator to read and an option hash. More...
 
 constructor (Qore::InputStream input, string encoding='UTF-8', hash spec, *hash opts)
 Instantiates the FixedLengthIterator object from an InputStream. More...
 
- Public Member Methods inherited from FixedLengthUtil::FixedLengthAbstractIterator
bool checkTransition (*string from, *string to)
 A verification function to be called for each line. This method can be overridden to achieve a begin-to-end validation of the whole input file. More...
 
 constructor (AbstractLineIterator li, hash spec, *hash opts)
 Instantiates the FixedLengthAbstractIterator object. More...
 
*hash getValue ()
 Returns the current record as a hash. More...
 
string identifyType (string input_line)
 Identify a fixed-length line type using identifyTypeImpl(), that may be overridden if necessary. More...
 
*string identifyTypeImpl (string input_line)
 Identify a fixed-length line type, given the raw line string. This method performs a lookup to a precalculated table based on line lengths (see constructor()). In case different criteria are needed, eg. when two line types in a spec have the same length and no unique resolving rule are specified, this method needs to be overridden, and will throw an exception, because the precalculated mapping will be empty. More...
 
bool next ()
 Moves the current line / record position to the next line / record; returns False if there are no more lines to iterate. More...
 
auto transform (auto value, hash type)
 parses the input value based on global configuration and the current field definition
 

Additional Inherited Members

- Private Member Methods inherited from FixedLengthUtil::FixedLengthAbstractIterator
*hash checkOptions (*hash opts)
 Validate and prepare global fixed-length options. More...
 
- Private Attributes inherited from FixedLengthUtil::FixedLengthAbstractIterator
hash m_resolve_by_length
 hash of type without rule, i.e.potentially conflicting records; key = record length, value = list of no-rule type names
 

Detailed Description

The FixedLengthIterator class allows CSV sources to be iterated on a record basis. The source of the input data is an AbstractLineIterator object or an InputStream.

Member Function Documentation

◆ constructor() [1/2]

FixedLengthUtil::FixedLengthIterator::constructor ( Qore::AbstractLineIterator  li,
hash  spec,
*hash  opts 
)

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

Parameters
liline iterator of CSV file to read
specFixed-length line specification; see Specification Hash for more information
optsGlobal options; see Global Options for more information

◆ constructor() [2/2]

FixedLengthUtil::FixedLengthIterator::constructor ( Qore::InputStream  input,
string  encoding = 'UTF-8',
hash  spec,
*hash  opts 
)

Instantiates the FixedLengthIterator object from an InputStream.

Example:
hash specs = (
"type1": (
"col1": ("length": 5, "type": "int"),
"col2": ("length": 2, "type": "string"),
),
"type2": (
"col3": ("length": 1, "type": "string"),
"col4": ("length": 3, "type": "string"),
"col5": ("length": 8, "type": "date", "format": "DDMMYYYY",
# "timezone": "Europe/Prague", # use global if omitted
),
),
);
hash global_options = (
"encoding" : "UTF-8",
"eol" : "\n",
"ignore_empty": True,
"timezone" : "Europe/Prague", # used if not overridden in a date field specification
);
StringInputStream input("00001AV\n00002BN\00003CZ\n");
FixedLengthIterator i(input, "UTF-8", specs, global_options);
while (i.next()) {
operation_with_hash(i.getValue())
}
Parameters
inputThe InputStream providing input data to process
encodingthe encoding of the input stream
specFixed-length line specification; see Specification Hash for more information
optsGlobal options; see Global Options for valid values