This class defines a line iterator for input streams.
More...
This class defines a line iterator for input streams.
- Since
- Qore 0.8.13
- Example: InputStreamLineIterator basic usage
1 FileInputStream fis(
"log.txt");
2 InputStreamLineIterator it(fis,
"\n");
4 printf(
"line %d = %n\n", it.index(), it.getLine());
- See also
- Qore::DataLineIterator
-
Qore::FileLineIterator
Creates the InputStreamLineIterator for iterating over the given InputStream
.
- Parameters
-
is | the InputStream to iterate over |
encoding | character encoding of the data from input stream; if not ASCII-compatible, all data will be converted to UTF-8; if not present, the default character encoding is assumed |
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" |
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 |
string Qore::InputStreamLineIterator::getEncoding |
( |
| ) |
|
string Qore::InputStreamLineIterator::getLine |
( |
| ) |
|
|
virtual |
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:
2 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
- InputStreamLineIterator::getValue()
Implements Qore::AbstractLineIterator.
string Qore::InputStreamLineIterator::getValue |
( |
| ) |
|
|
virtual |
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:
2 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
- InputStreamLineIterator::getLine()
Implements Qore::AbstractLineIterator.
int Qore::InputStreamLineIterator::index |
( |
| ) |
|
|
virtual |
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:
2 printf(
"+ %d: %y\n", i.index(), i.getValue());
Implements Qore::AbstractLineIterator.
bool Qore::InputStreamLineIterator::next |
( |
| ) |
|
|
virtual |
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.
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:
2 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 |
Implements Qore::AbstractLineIterator.
bool Qore::InputStreamLineIterator::valid |
( |
| ) |
|
|
virtual |