3 #ifndef INCLUDE_NN_NLIB_TEXTREADER_H_ 4 #define INCLUDE_NN_NLIB_TEXTREADER_H_ 27 if (cur_ == bufend_) {
29 if (cur_ == bufend_)
return -1;
31 int rval = *
reinterpret_cast<unsigned char*
>(cur_);
35 pos_of_line_ = pos_of_buf_ + (cur_ - &buf_[0]);
40 if (!utf32_cache_) ConstructUtf32Cache();
41 cur_ += utf8_bytecount_;
42 rval =
static_cast<int>(utf32_cache_);
47 if (cur_ == bufend_) {
49 if (cur_ == bufend_)
return -1;
51 int rval = *
reinterpret_cast<unsigned char*
>(cur_);
52 if (!(rval & 0x80))
return rval;
53 if (!utf32_cache_) ConstructUtf32Cache();
54 return static_cast<int>(utf32_cache_);
58 if (cur_ + 1 < bufend_) {
59 unsigned char c = *
reinterpret_cast<unsigned char*
>(cur_);
60 if (c >
' ')
return 0;
63 c = *
reinterpret_cast<unsigned char*
>(cur_);
68 return this->SkipWs_(1);
71 return this->SkipWs_(0);
73 bool ReadUntil(
size_t* len,
char* buf,
size_t n,
char delim) NLIB_NOEXCEPT
NLIB_NONNULL;
75 bool ReadUntil(
size_t* len,
char (&buf)[N],
char delim) NLIB_NOEXCEPT {
76 return this->ReadUntil(len, &buf[0], N, delim);
79 bool ReadUntil(
size_t* len,
char* buf,
size_t n, T pred)
NLIB_NOEXCEPT;
80 template <
class T,
size_t N>
81 bool ReadUntil(
size_t* len,
char (&buf)[N], T pred) NLIB_NOEXCEPT {
82 return this->ReadUntil(len, buf, N, pred);
84 size_t ReadDecimalString(
char* buf,
size_t n) NLIB_NOEXCEPT
NLIB_NONNULL;
87 return this->ReadDecimalString(buf, N);
89 bool Proceed(
const char* str,
size_t n) NLIB_NOEXCEPT
NLIB_NONNULL;
91 NLIB_ASSERT(!(c & 0x80) && c != 0x0A);
92 if (cur_ == bufend_) {
94 if (cur_ == bufend_)
return false;
96 if (*cur_ != c)
return false;
103 if (errno_ == 0) errno_ = e;
107 int GetLine() const NLIB_NOEXCEPT {
return line_; }
109 return static_cast<int>((cur_ - &buf_[0]) + 1 + pos_of_buf_ - pos_of_line_);
114 char* GetCur() NLIB_NOEXCEPT {
return cur_; }
115 char* GetBufEnd() NLIB_NOEXCEPT {
return bufend_; }
116 void SetBufEnd(
char* p) NLIB_NOEXCEPT { bufend_ = p; }
122 void FillBuffer() NLIB_NOEXCEPT { this->FillBuffer_(); }
128 char buf_[512 + 3 + 1];
132 size_t utf8_bytecount_;
143 bool TextReader::ReadUntil(
size_t* len,
char* buf,
size_t n, T pred) NLIB_NOEXCEPT {
151 char* pend = buf + n;
153 if (cur_ == bufend_) {
155 if (cur_ == bufend_) {
161 while (p != pend && cur_ != bufend_) {
162 if ((*reinterpret_cast<unsigned char*>(cur_) & 0xC0) != 0x80 &&
163 pred((
const char*)cur_)) {
172 if (cur_ != bufend_ && (*reinterpret_cast<unsigned char*>(cur_) & 0xC0) == 0x80) {
176 }
while ((*reinterpret_cast<unsigned char*>(cur_) & 0xC0) == 0x80);
186 #endif // INCLUDE_NN_NLIB_TEXTREADER_H_ bool ReadUntil(size_t *len, char(&buf)[N], char delim) noexcept
Calls ReadUntil(len, buf, N, delim).
#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.
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.
bool ReadUntil(size_t *len, char(&buf)[N], T pred) noexcept
Calls ReadUntil(len, buf, N, pred).
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.