|
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 |
| A template overload of the above function.
|
|
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 |
| A template overload of the above function. More...
|
|
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 |
| A template overload of the above function.
|
|
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 the object has been initialized and an error has not occurred inside, or returns false if an error has occurred inside.
|
|
|
| TextReader () noexcept |
| Instantiates the object with default parameters (default constructor). Requires initialization with Init() after execution.
|
|
virtual | ~TextReader () noexcept |
| Destructor. The stream is not closed.
|
|
errno_t | Init () noexcept |
| Initializes an object. Returns 0 if successful. More...
|
|
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.
- Sample code is provided below. Note that you have to close or destruct
TextReader
before closing the stream. const char* str = "\xf0\x9f\xa4\xa9\xf0\x9f\xa7\x9d multibyte";
SUCCEED_IF(reader.
Init() == 0);
SUCCEED_IF(reader.
Open(&is) == 0);
int c;
while ((c = reader.Read()) >= 0) {
}
(void)is.Close();
- 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_();
}
Definition at line 33 of file TextReader.h.