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
ReadUntil(len, buf, N, pred) を呼び出します。
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
#define NLIB_SAFE_BOOL(class_name, exp)
クラス内に安全なoperator bool()を定義します。 可能であればC++11のexplicit boolを利用します。 ...
int Read() noexcept
ストリームから1文字を読み込み、UTF-32で返します。
InputStream * GetStream() noexcept
テキストリーダーが書き込みを行うストリームを取得します。
int GetColumn() const noexcept
現在の桁を取得します。
errno_t GetErrorValue() const noexcept
読み込みが失敗した際に、エラーの原因を取得できます。
size_t ReadDecimalString(char(&buf)[N]) noexcept
ReadDecimalString(buf, N) を呼び出します。
bool Proceed(char c) noexcept
文字c の分だけストリームを進めます。
bool ReadUntil(size_t *len, nlib_utf8_t(&buf)[N], char delim) noexcept
ReadUntil(len, buf, N, delim) を呼び出します。
errno_tをラップするクラスです。Visual Studioのデバッガ上での表示を改善します。
int GetLine() const noexcept
現在の行番号を取得します。
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
int SkipWs() noexcept
ストリーム内の空白(スペース,改行,タブ,復帰)文字を読み飛ばして、読み飛ばした空白の数を返します。 ...
void SetError(errno_t e) const noexcept
エラー値を設定します。
int Peek() noexcept
ストリームの先頭の1文字を、UTF-32で返します。