| Qore Programming Language Reference Manual 2.2.0

Loading...
Searching...
No Matches
Public Member Functions | List of all members
Qore::DataLineIterator Class Reference

This class defines a line iterator for string data. More...

`#include <QC_DataLineIterator.dox.h>`

Inheritance diagram for Qore::DataLineIterator:
[legend]

## Public Member Functions
| constructor (string str, *string eol, bool trim=True)
| creates the DataLineIterator based on the string given
| copy ()
| Creates a new DataLineIterator object, based on the same object being iterated in the original object.
string | getEncoding ()
| Returns the character encoding for the DataLineIterator.
string | getLine ()
| returns the current line in the data or throws an `ITERATOR-ERROR` exception if the iterator is invalid
string | getValue ()
| returns the current line in the data or throws an `ITERATOR-ERROR` exception if the iterator is invalid
int | index ()
| returns the current iterator line number in the data (the first line is line 1) or 0 if not pointing at a valid element
bool | next ()
| Moves the current position to the next line in the data; returns False if there are no more lines to read; if the iterator is not pointing at a valid element before this call, the iterator will be positioned to the beginning of the data.
| reset ()
| Reset the iterator instance to its initial state.
bool | valid ()
| returns True if the iterator is currently pointing at a valid element, False if not
Public Member Functions inherited from Qore::AbstractLineIterator
abstract string | getLine ()
| Returns the current line in the data or throws an `INVALID-ITERATOR` exception if the iterator is invalid.
list< string > | getSplitLine (string sep, string quote, string eol="\n", bool trim_unquoted=False)
| Returns the current line and splits the string into a list of components based on a separator string and a quote character.
abstract string | getValue ()
| Returns the current line in the data or throws an `INVALID-ITERATOR` exception if the iterator is invalid.
abstract int | index ()
| Returns the current iterator line number (the first line is line 1) or 0 if not pointing at a valid element.
abstract bool | next ()
| Moves the current position to the next line; returns False if there are no more lines to read.
abstract bool | valid ()
| Returns True if the iterator is currently pointing at a valid element, False if not.
Public Member Functions inherited from Qore::AbstractIterator
abstract auto | getValue ()
| returns the current value
abstract bool | next ()
| Moves the current position to the next element; returns False if there are no more elements.
abstract bool | valid ()
| returns True if the iterator is currently pointing at a valid element, False if not

## Detailed Description

This class defines a line iterator for string data.

Since
  Qore 0.8.12

Example: DataLineIterator basic usage
  string str = "a2ps-4.13-1332.1.x86_64
  a2ps-devel-4.13-1332.1.x86_64
  aaa_base-11.3-7.2.x86_64";
  DataLineIterator it(str);
  while (it.next()) {
  printf("line %d = %n\n", it.index(), it.getValue());
  }
  line 1 = "a2ps-4.13-1332.1.x86_64"
  line 2 = "a2ps-devel-4.13-1332.1.x86_64"
  line 3 = "aaa_base-11.3-7.2.x86_64"

See also
  Qore::InputStreamLineIterator
  Qore::FileLineIterator

## Member Function Documentation

## ◆ constructor()

Qore::DataLineIterator::constructor | ( | string | str,
|  | *string | eol,
|  | bool | trim = True )

creates the DataLineIterator based on the string given

Parameters

  str | the string to iterate over; note that if this string is in a non-ascii-compatible character encoding, it will be converted to UTF-8 for processing in the constructor and the UTF-8 version of the string will be used for iterating in this object
  eol | the optional end of line character(s) to use to detect lines in the data; if this string is not passed, then the end of line character(s) are detected automatically, and can be either `"\n"`, `"\r"`, or `"\r\n"`; if this string is passed and has a different character encoding from this object's (as determined by the `encoding` parameter), then it will be converted to the DataLineIterator's character encoding
  trim | if True the string return values for the lines iterated will be trimmed of the eol bytes

Exceptions

  ENCODING-CONVERSION-ERROR | this exception could be thrown if the eol argument has a different character encoding from the data's and an error occurs during encoding conversion

## ◆ copy()

Qore::DataLineIterator::copy | ( |  | ) |

Creates a new DataLineIterator object, based on the same object being iterated in the original object.

Example:
  DataLineIterator ni = i.copy();

## ◆ getEncoding()

string Qore::DataLineIterator::getEncoding | ( |  | ) |

Returns the character encoding for the DataLineIterator.

Code Flags:
  CONSTANT

Example:
  string encoding = f.getEncoding();

Returns
  the character encoding for the DataLineIterator

## ◆ getLine()

string Qore::DataLineIterator::getLine | ( |  | ) |

returns the current line in the data or throws an `ITERATOR-ERROR` exception if the iterator is invalid

Returns
  the current line in the data or throws an `ITERATOR-ERROR` exception if the iterator is invalid

Code Flags:
  RET_VALUE_ONLY

Example:
  while (i.next()) {
  printf("+ %y\n", i.getLine());
  }

Exceptions

  ITERATOR-ERROR | the iterator is not pointing at a valid element
  ITERATOR-THREAD-ERROR | this exception is thrown if this method is called from any thread other than the thread that created the object

See also
  DataLineIterator::getValue()

## ◆ getValue()

string Qore::DataLineIterator::getValue | ( |  | ) |

returns the current line in the data or throws an `ITERATOR-ERROR` exception if the iterator is invalid

Returns
  the current line in the data or throws an `ITERATOR-ERROR` exception if the iterator is invalid

Code Flags:
  RET_VALUE_ONLY

Example:
  while (i.next()) {
  printf("+ %y\n", i.getValue());
  }

Exceptions

  ITERATOR-ERROR | the iterator is not pointing at a valid element
  ITERATOR-THREAD-ERROR | this exception is thrown if this method is called from any thread other than the thread that created the object

See also
  DataLineIterator::getLine()

## ◆ index()

int Qore::DataLineIterator::index | ( |  | ) |

returns the current iterator line number in the data (the first line is line 1) or 0 if not pointing at a valid element

Returns
  the current iterator line number in the data (the first line is line 1) or 0 if not pointing at a valid element

Code Flags:
  CONSTANT

Example:
  while (i.next()) {
  printf("+ %d: %y\n", i.index(), i.getValue());
  }

## ◆ next()

bool Qore::DataLineIterator::next | ( |  | ) |

Moves the current position to the next line in the data; returns False if there are no more lines to read; if the iterator is not pointing at a valid element before this call, the iterator will be positioned to the beginning of the data.

This method will return True again after it returns False once if data is not empty, otherwise it will always return False The iterator object should not be used after this method returns False

Returns
  False if there are no more lines in the data (in which case the iterator object is invalid and should not be used); True if successful (meaning that the iterator object is valid)

Example:
  while (i.next()) {
  printf("line: %y\n", i.getValue());
  }

Exceptions

  ITERATOR-THREAD-ERROR | this exception is thrown if this method is called from any thread other than the thread that created the object

## ◆ reset()

Qore::DataLineIterator::reset | ( |  | ) |

Reset the iterator instance to its initial state.

Reset the iterator instance to its initial state

Example
  i.reset();

Exceptions

  ITERATOR-THREAD-ERROR | this exception is thrown if this method is called from any thread other than the thread that created the object

## ◆ valid()

bool Qore::DataLineIterator::valid | ( |  | ) |

returns True if the iterator is currently pointing at a valid element, False if not

Returns
  True if the iterator is currently pointing at a valid element, False if not

Code Flags:
  CONSTANT

Example:
  if (i.valid())
  printf("current value: %y\n", i.getValue());