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
ReadUntil(len, buf, N, delim) を呼び出します。
#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 の分だけストリームを進めます。
errno_tをラップするクラスです。Visual Studioのデバッガ上での表示を改善します。
int GetLine() const noexcept
現在の行番号を取得します。
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
bool ReadUntil(size_t *len, char(&buf)[N], T pred) noexcept
ReadUntil(len, buf, N, pred) を呼び出します。
int SkipWs() noexcept
ストリーム内の空白(スペース,改行,タブ,復帰)文字を読み飛ばして、読み飛ばした空白の数を返します。 ...
void SetError(errno_t e) const noexcept
エラー値を設定します。
int Peek() noexcept
ストリームの先頭の1文字を、UTF-32で返します。