16 #ifndef INCLUDE_NN_NLIB_TEXTREADER_H_ 17 #define INCLUDE_NN_NLIB_TEXTREADER_H_ 40 if (cur_ == bufend_) {
42 if (cur_ == bufend_)
return -1;
44 int rval = *
reinterpret_cast<unsigned char*
>(cur_);
48 pos_of_line_ = pos_of_buf_ + (cur_ - &buf_[0]);
53 if (!utf32_cache_) ConstructUtf32Cache();
54 cur_ += utf8_bytecount_;
55 rval =
static_cast<int>(utf32_cache_);
60 if (cur_ == bufend_) {
62 if (cur_ == bufend_)
return -1;
64 int rval = *
reinterpret_cast<unsigned char*
>(cur_);
65 if (!(rval & 0x80))
return rval;
66 if (!utf32_cache_) ConstructUtf32Cache();
67 return static_cast<int>(utf32_cache_);
71 if (cur_ + 1 < bufend_) {
72 unsigned char c = *
reinterpret_cast<unsigned char*
>(cur_);
73 if (c >
' ')
return 0;
76 c = *
reinterpret_cast<unsigned char*
>(cur_);
81 return this->SkipWs_(1);
84 return this->SkipWs_(0);
89 return this->ReadUntil(len, &buf[0], N, delim);
93 template <
class T,
size_t N>
95 return this->ReadUntil(len, buf, N, pred);
97 size_t ReadDecimalString(
char* buf,
size_t n) NLIB_NOEXCEPT
NLIB_NONNULL;
100 return this->ReadDecimalString(buf, N);
104 NLIB_ASSERT(!(c & 0x80) && c != 0x0A);
105 if (cur_ == bufend_) {
107 if (cur_ == bufend_)
return false;
109 if (*cur_ != c)
return false;
116 if (errno_ == 0) errno_ = e;
120 int GetLine() const NLIB_NOEXCEPT {
return line_; }
122 return static_cast<int>((cur_ - &buf_[0]) + 1 + pos_of_buf_ - pos_of_line_);
127 char* GetCur() NLIB_NOEXCEPT {
return cur_; }
128 char* GetBufEnd() NLIB_NOEXCEPT {
return bufend_; }
129 void SetBufEnd(
char* p) NLIB_NOEXCEPT { bufend_ = p; }
135 void FillBuffer() NLIB_NOEXCEPT { this->FillBuffer_(); }
141 char buf_[512 + 3 + 1];
145 size_t utf8_bytecount_;
156 bool TextReader::ReadUntil(
size_t* len,
nlib_utf8_t* buf,
size_t n, T pred) NLIB_NOEXCEPT {
164 char* pend = buf + n;
166 if (cur_ == bufend_) {
168 if (cur_ == bufend_) {
174 while (p != pend && cur_ != bufend_) {
175 if ((*reinterpret_cast<unsigned char*>(cur_) & 0xC0) != 0x80 &&
176 pred((
const char*)cur_)) {
185 if (cur_ != bufend_ && (*reinterpret_cast<unsigned char*>(cur_) & 0xC0) == 0x80) {
189 }
while ((*reinterpret_cast<unsigned char*>(cur_) & 0xC0) == 0x80);
199 #endif // INCLUDE_NN_NLIB_TEXTREADER_H_ bool ReadUntil(size_t *len, nlib_utf8_t(&buf)[N], T pred) noexcept
Calls ReadUntil(len, buf, N, pred).
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
#define NLIB_SAFE_BOOL(class_name, exp)
Defines a safe operator bool function in the class. Uses the C++11 explicit bool if it is available f...
int Read() noexcept
Reads one character from the stream and returns UTF-32 data.
InputStream * GetStream() noexcept
Gets the stream for the text reader to read.
int GetColumn() const noexcept
Gets the current column.
errno_t GetErrorValue() const noexcept
This function can get the cause of the error when reading has failed.
size_t ReadDecimalString(char(&buf)[N]) noexcept
Calls ReadDecimalString(buf, N).
bool Proceed(char c) noexcept
Advances the stream by the amount of the character specified by c.
bool ReadUntil(size_t *len, nlib_utf8_t(&buf)[N], char delim) noexcept
Calls ReadUntil(len, buf, N, delim).
The class for reading text from streams.
Class that wraps errno_t. This class improves visual representations in the Visual Studio debugger...
int GetLine() const noexcept
Gets the current line number.
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
A file that contains the configuration information for each development environment.
int SkipWs() noexcept
Skips white-space characters (space, newline, tab, and return) in the stream and returns the number t...
void SetError(errno_t e) const noexcept
Sets an error value.
int Peek() noexcept
Returns one character from the start of the stream in UTF-32.