X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fio%2Ftoken.cpp;h=a2ad44c918f0a834a409aa94fc36f4c3877eaabe;hb=5bc84befaa51b81f8f4cfc7d447c553bb471953a;hp=07a5e981cd889d01d5920797ee0a4d63dd0ff604;hpb=73d4dd2d78eda1e2f8889d1913a97a60cec86876;p=blank.git diff --git a/src/io/token.cpp b/src/io/token.cpp index 07a5e98..a2ad44c 100644 --- a/src/io/token.cpp +++ b/src/io/token.cpp @@ -163,7 +163,7 @@ void Tokenizer::ReadString() { current.value += '\n'; break; case 'r': - current.value += '\t'; + current.value += '\r'; break; case 't': current.value += '\t'; @@ -286,7 +286,7 @@ const Token &TokenStreamReader::Peek() { } -void TokenStreamReader::Assert(Token::Type t) { +void TokenStreamReader::Assert(Token::Type t) const { if (GetType() != t) { stringstream s; s << "unexpected token in input stream: expected " << t << ", but got " << in.Current(); @@ -412,9 +412,13 @@ void TokenStreamReader::ReadQuat(glm::quat &q) { bool TokenStreamReader::GetBool() { Next(); + return AsBool(); +} + +bool TokenStreamReader::AsBool() const { switch (GetType()) { case Token::NUMBER: - return GetInt() != 0; + return AsInt() != 0; case Token::IDENTIFIER: case Token::STRING: if (GetValue() == "true" || GetValue() == "yes" || GetValue() == "on") { @@ -435,18 +439,30 @@ bool TokenStreamReader::GetBool() { float TokenStreamReader::GetFloat() { Next(); + return AsFloat(); +} + +float TokenStreamReader::AsFloat() const { Assert(Token::NUMBER); return stof(GetValue()); } int TokenStreamReader::GetInt() { Next(); + return AsInt(); +} + +int TokenStreamReader::AsInt() const { Assert(Token::NUMBER); return stoi(GetValue()); } unsigned long TokenStreamReader::GetULong() { Next(); + return AsULong(); +} + +unsigned long TokenStreamReader::AsULong() const { Assert(Token::NUMBER); return stoul(GetValue()); }