Qore Programming Language Reference Manual
0.8.12.3
|
This class defines a line iterator for text files. More...
Public Member Functions | |
constructor (string path, *string encoding, *string eol, bool trim=True) | |
opens the given file for reading with the given options and creates the FileLineIterator object More... | |
copy () | |
Creates a new FileLineIterator object, based on the same object being iterated in the original object (the original file is reopened) More... | |
string | getEncoding () |
Returns the character encoding for the FileLineIterator. More... | |
string | getFileName () |
returns the file path/name used to open the file More... | |
string | getLine () |
returns the current line in the file or throws an INVALID-ITERATOR exception if the iterator is invalid More... | |
int | getPos () |
Returns the current file position as an integer giving the offset in bytes from the beginning of the file (starting from zero) More... | |
string | getValue () |
returns the current line in the file or throws an INVALID-ITERATOR exception if the iterator is invalid More... | |
hash | hstat () |
returns Stat Hash of hstat() of the underlying file More... | |
int | index () |
returns the current iterator line number in the file (the first line is line 1) or 0 if not pointing at a valid element More... | |
bool | isTty () |
returns True if the FileLineIterator is connected to a terminal device, False if not More... | |
bool | next () |
Moves the current position to the next line in the file; 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 file. More... | |
reset () | |
Reset the iterator instance to its initial state. More... | |
list | stat () |
returns Stat List of stat() of the underlying file More... | |
bool | valid () |
returns True if the iterator is currently pointing at a valid element, False if not More... | |
This class defines a line iterator for text files.
Qore::FileLineIterator::constructor | ( | string | path, |
*string | encoding, | ||
*string | eol, | ||
bool | trim = True |
||
) |
opens the given file for reading with the given options and creates the FileLineIterator object
path | the path to open for reading |
encoding | the character encoding tag for underlying file and therefore the string return values for the lines iterated with this class; if not present, the default character encoding is assumed |
eol | the optional end of line character(s) to use to detect lines in the file; 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" (the last one is only automatically detected when not connected to a terminal device in order to keep the I/O from stalling); 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 FileLineIterator's character encoding |
trim | if True the string return values for the lines iterated will be trimmed of the eol bytes |
FILELINEITERATOR-OPEN-ERROR | the given file cannot be opened for reading (arg will be assigned to the errno value) |
ENCODING-CONVERSION-ERROR | this exception could be thrown if the eol argument has a different character encoding from the File's and an error occurs during encoding conversion |
ILLEGAL-EXPRESSION | FileLineIterator::constructor() cannot be called with a TTY target when %no-terminal-io is set |
Qore::FileLineIterator::copy | ( | ) |
Creates a new FileLineIterator object, based on the same object being iterated in the original object (the original file is reopened)
FILELINEITERATOR-COPY-ERROR | the original file cannot be reopened for reading (arg will be assigned to the errno value) |
ILLEGAL-EXPRESSION | FileLineIterator::constructor() cannot be called with a TTY target when %no-terminal-io is set |
string Qore::FileLineIterator::getEncoding | ( | ) |
Returns the character encoding for the FileLineIterator.
string Qore::FileLineIterator::getFileName | ( | ) |
returns the file path/name used to open the file
string Qore::FileLineIterator::getLine | ( | ) |
returns the current line in the file or throws an INVALID-ITERATOR
exception if the iterator is invalid
INVALID-ITERATOR
exception if the iterator is invalidINVALID-ITERATOR | 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 |
int Qore::FileLineIterator::getPos | ( | ) |
Returns the current file position as an integer giving the offset in bytes from the beginning of the file (starting from zero)
ILLEGAL-EXPRESSION | this exception is only thrown if called with a system constant object (stdin, stdout, stderr) when no-terminal-io is set |
|
virtual |
returns the current line in the file or throws an INVALID-ITERATOR
exception if the iterator is invalid
INVALID-ITERATOR
exception if the iterator is invalidINVALID-ITERATOR | 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 |
Implements Qore::AbstractIterator.
hash Qore::FileLineIterator::hstat | ( | ) |
int Qore::FileLineIterator::index | ( | ) |
returns the current iterator line number in the file (the first line is line 1) or 0 if not pointing at a valid element
bool Qore::FileLineIterator::isTty | ( | ) |
returns True if the FileLineIterator is connected to a terminal device, False if not
|
virtual |
Moves the current position to the next line in the file; 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 file.
This method will return True again after it returns False once if file is not empty, otherwise it will always return False The iterator object should not be used after this method returns False
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::AbstractIterator.
Qore::FileLineIterator::reset | ( | ) |
list Qore::FileLineIterator::stat | ( | ) |
|
virtual |