16 #ifndef INCLUDE_NN_NLIB_TEXTREADER_H_ 17 #define INCLUDE_NN_NLIB_TEXTREADER_H_ 44 if (cur_ + 1 < bufend_) {
45 unsigned char c = *
reinterpret_cast<unsigned char*
>(cur_);
46 if (c >
' ')
return 0;
49 c = *
reinterpret_cast<unsigned char*
>(cur_);
54 return this->SkipWs_(1);
57 return this->SkipWs_(0);
62 return this->ReadUntil(len, &buf[0], N, delim);
67 template<
class T,
size_t N>
69 return this->ReadUntil(len, buf, N, pred);
74 return this->ReadDecimalString(buf, N);
78 NLIB_ASSERT(!(c & 0x80) && c != 0x0A);
79 if (cur_ == bufend_) {
81 if (cur_ == bufend_)
return false;
83 if (*cur_ != c)
return false;
90 if (errno_ == 0) errno_ = e;
96 return static_cast<int>((cur_ - &buf_[0]) + 1 + pos_of_buf_ - pos_of_line_);
114 char buf_[512 + 3 + 1];
118 size_t utf8_bytecount_;
119 InputStream* stream_;
120 mutable ErrnoT errno_;
137 char* pend = buf + n;
139 if (cur_ == bufend_) {
141 if (cur_ == bufend_) {
147 while (p != pend && cur_ != bufend_) {
148 if ((*reinterpret_cast<unsigned char*>(cur_) & 0xC0) != 0x80 &&
149 pred((
const char*)cur_)) {
158 if (cur_ != bufend_ && (*reinterpret_cast<unsigned char*>(cur_) & 0xC0) == 0x80) {
162 }
while ((*reinterpret_cast<unsigned char*>(cur_) & 0xC0) == 0x80);
172 #endif // INCLUDE_NN_NLIB_TEXTREADER_H_ bool ReadUntil(size_t *len, nlib_utf8_t(&buf)[N], T pred) noexcept
A template overload of the above function.
#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...
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
A template overload of the above function.
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
A template overload of the above function.
The class for reading text from streams.
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.
bool Proceed(StringView &str, const StringView &prefix) noexcept
If str starts with prefix, it is allowed to go forward by the length of that string.
int SkipWs() noexcept
Skips white-space characters (space, newline, tab, and return) in the stream and returns the number t...
bool Read(BinaryReader *r, T *x)
You can read to user-defined class objects by specializing this function template.