|
errno_t | Init () noexcept |
| Initializes the text reader. More...
|
|
errno_t | Open (InputStream *stream) noexcept |
| Opens a text reader with a stream specified. More...
|
|
int | Read () noexcept |
| Reads one character from the stream and returns UTF-32 data. More...
|
|
int | Peek () noexcept |
| Returns one character from the start of the stream in UTF-32. More...
|
|
int | SkipWs () noexcept |
| Skips white-space characters (space, newline, tab, and return) in the stream and returns the number that were skipped. More...
|
|
bool | ReadUntil (size_t *len, nlib_utf8_t *buf, size_t n, char delim) noexcept |
| Reads as many as n bytes of UTF-8 characters until delim and stores them in buf. More...
|
|
template<size_t N> |
bool | ReadUntil (size_t *len, nlib_utf8_t(&buf)[N], char delim) noexcept |
| Calls ReadUntil(len, buf, N, delim) .
|
|
template<class T > |
bool | ReadUntil (size_t *len, nlib_utf8_t *buf, size_t n, T pred) noexcept |
| Reads as many as n bytes of UTF-8 characters and stores them in buf. More...
|
|
template<class T , size_t N> |
bool | ReadUntil (size_t *len, nlib_utf8_t(&buf)[N], T pred) noexcept |
| Calls ReadUntil(len, buf, N, pred) .
|
|
size_t | ReadDecimalString (char *buf, size_t n) noexcept |
| Reads as many as n of the characters 0 through 9 and stores them in buf. More...
|
|
template<size_t N> |
size_t | ReadDecimalString (char(&buf)[N]) noexcept |
| Calls ReadDecimalString(buf, N) .
|
|
bool | Proceed (const nlib_utf8_t *str, size_t n) noexcept |
| Advances the stream by the amount of the text string str. More...
|
|
bool | Proceed (char c) noexcept |
| Advances the stream by the amount of the character specified by c. More...
|
|
bool | ProceedEx (const nlib_utf8_t *str) noexcept |
| Advances the stream by the amount of the text string str. There is no limit on the length of the text string, and the position of the stream might be changed even if it does not match. More...
|
|
bool | Close () noexcept |
| Closes the text reader. More...
|
|
void | SetError (errno_t e) const noexcept |
| Sets an error value. More...
|
|
errno_t | GetErrorValue () const noexcept |
| This function can get the cause of the error when reading has failed. More...
|
|
InputStream * | GetStream () noexcept |
| Gets the stream for the text reader to read. More...
|
|
int | GetLine () const noexcept |
| Gets the current line number. More...
|
|
int | GetColumn () const noexcept |
| Gets the current column. More...
|
|
| operator bool () const |
| Returns true if no internal error has occurred.
|
|
|
| TextReader () noexcept |
| Instantiates the object with default parameters (default constructor).
|
|
virtual | ~TextReader () noexcept |
| Destructor. The stream is not closed.
|
|
The class for reading text from streams.
- Description
- Reads a UTF-8 text string from a stream and gets one character at a time (UTF-32 or UTF-16).
- Newline strings are processed as follows.
-
CRLF is passed as LF.
-
CR is passed as LF.
-
LF is passed as LF.
- If verbose UTF-8 is detected, an error is generated (
EILSEQ
). An error (EILSEQ
) is also generated if UTF-8 corresponding to U+D800-U+DFFF is detected. const char str[] = "multibyte \r\nstring";
MemoryInputStream istr;
istr.Init(str);
int c;
while ((c = r.Read()) != -1) {
}
- You can add a check for UTF-8 text by inheriting
TextReader
and overriding a FillBuffer_
member function. The TextReader
class checks if UTF-8 is enabled and processes newline codes.
- The following code is a rough sketch of the implementation of the derived class.
TextReader::FillBuffer_();
}
- Examples:
- misc/readfile/readfile.cpp, and misc/writefile/writefile.cpp.
Definition at line 33 of file TextReader.h.