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 if the character-encoding is ASCII-compatible, the end of line character(s) are detected automatically from "\n", "\r", or "\r\n"; if the stream uses a non-ASCII-compatible character encoding, then "\n" is assumed |
| trim | if True the string return values for the lines iterated will be trimmed of the eol bytes |
| bufsize | the size of the buffer for the internal Constants in bytes; must be a positive integer |
- Exceptions
-
| STREAM-BUFFER-ERROR | an invalid stream buffer size was specified; the buffer size must be a positive integer |
| 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 |
- Note
- this variant of the InputStreamLineIterator::constructor creates a Constants to read the input data
Creates the InputStreamLineIterator for iterating data from the given StreamReader.
- Parameters
-
| sr | the StreamReader used as a source of data to iterate over |
| eol | the optional end of line character(s) to use to detect lines in the data; if this string is not passed, then if the character-encoding is ASCII-compatible, the end of line character(s) are detected automatically from "\n", "\r", or "\r\n"; if the stream uses a non-ASCII-compatible character encoding, then "\n" is assumed |
| 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.
| StreamReader Qore::InputStreamLineIterator::getStreamReader |
( |
| ) |
|
Returns the StreamReader object used internally.
- Example:
1 StreamReader sr = i.getStreamReader();
- Returns
- the StreamReader object used internally
| 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 |