Use int instead of char in CLI config parser (#3976)

This commit is contained in:
Philip Hyunsu Cho 2018-12-07 01:00:21 -08:00 committed by GitHub
parent 4f26053b09
commit 9af6b689d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -58,12 +58,12 @@ class ConfigReaderBase {
* \brief to be implemented by subclass, * \brief to be implemented by subclass,
* get next token, return EOF if end of file * get next token, return EOF if end of file
*/ */
virtual char GetChar() = 0; virtual int GetChar() = 0;
/*! \brief to be implemented by child, check if end of stream */ /*! \brief to be implemented by child, check if end of stream */
virtual bool IsEnd() = 0; virtual bool IsEnd() = 0;
private: private:
char ch_buf_; int ch_buf_;
std::string s_name_, s_val_, s_buf_; std::string s_name_, s_val_, s_buf_;
inline void SkipLine() { inline void SkipLine() {
@ -79,7 +79,7 @@ class ConfigReaderBase {
case '\"': return; case '\"': return;
case '\r': case '\r':
case '\n': LOG(FATAL)<< "ConfigReader: unterminated string"; case '\n': LOG(FATAL)<< "ConfigReader: unterminated string";
default: *tok += ch_buf_; default: *tok += static_cast<char>(ch_buf_);
} }
} }
LOG(FATAL) << "ConfigReader: unterminated string"; LOG(FATAL) << "ConfigReader: unterminated string";
@ -89,7 +89,7 @@ class ConfigReaderBase {
switch (ch_buf_) { switch (ch_buf_) {
case '\\': *tok += this->GetChar(); break; case '\\': *tok += this->GetChar(); break;
case '\'': return; case '\'': return;
default: *tok += ch_buf_; default: *tok += static_cast<char>(ch_buf_);
} }
} }
LOG(FATAL) << "unterminated string"; LOG(FATAL) << "unterminated string";
@ -128,7 +128,7 @@ class ConfigReaderBase {
if (tok->length() != 0) return new_line; if (tok->length() != 0) return new_line;
break; break;
default: default:
*tok += ch_buf_; *tok += static_cast<char>(ch_buf_);
ch_buf_ = this->GetChar(); ch_buf_ = this->GetChar();
break; break;
} }
@ -152,7 +152,7 @@ class ConfigStreamReader: public ConfigReaderBase {
explicit ConfigStreamReader(std::istream &fin) : fin_(fin) {} explicit ConfigStreamReader(std::istream &fin) : fin_(fin) {}
protected: protected:
char GetChar() override { int GetChar() override {
return fin_.get(); return fin_.get();
} }
/*! \brief to be implemented by child, check if end of stream */ /*! \brief to be implemented by child, check if end of stream */