diff --git a/externals/simplecpp/simplecpp.cpp b/externals/simplecpp/simplecpp.cpp index 47a0b631a..f94710b35 100644 --- a/externals/simplecpp/simplecpp.cpp +++ b/externals/simplecpp/simplecpp.cpp @@ -45,6 +45,11 @@ static bool isHex(const std::string &s) return s.size()>2 && (s.compare(0,2,"0x")==0 || s.compare(0,2,"0X")==0); } +static bool isOct(const std::string &s) +{ + return s.size()>1 && (s[0]=='0') && (s[1] >= '0') && (s[1] < '8'); +} + static const simplecpp::TokenString DEFINE("define"); static const simplecpp::TokenString UNDEF("undef"); @@ -76,9 +81,12 @@ static long long stringToLL(const std::string &s) { long long ret; const bool hex = isHex(s); - std::istringstream istr(hex ? s.substr(2) : s); + const bool oct = isOct(s); + std::istringstream istr(hex ? s.substr(2) : oct ? s.substr(1) : s); if (hex) istr >> std::hex; + else if (oct) + istr >> std::oct; istr >> ret; return ret; } @@ -87,9 +95,12 @@ static unsigned long long stringToULL(const std::string &s) { unsigned long long ret; const bool hex = isHex(s); - std::istringstream istr(hex ? s.substr(2) : s); + const bool oct = isOct(s); + std::istringstream istr(hex ? s.substr(2) : oct ? s.substr(1) : s); if (hex) istr >> std::hex; + else if (oct) + istr >> std::oct; istr >> ret; return ret; } @@ -769,7 +780,7 @@ void simplecpp::TokenList::combineOperators() } // match: [0-9.]+E [+-] [0-9]+ const char lastChar = tok->str()[tok->str().size() - 1]; - if (tok->number && !isHex(tok->str()) && (lastChar == 'E' || lastChar == 'e') && tok->next && tok->next->isOneOf("+-") && tok->next->next && tok->next->next->number) { + if (tok->number && !isHex(tok->str()) && !isOct(tok->str()) && (lastChar == 'E' || lastChar == 'e') && tok->next && tok->next->isOneOf("+-") && tok->next->next && tok->next->next->number) { tok->setstr(tok->str() + tok->next->op + tok->next->next->str()); deleteToken(tok->next); deleteToken(tok->next); @@ -830,7 +841,7 @@ void simplecpp::TokenList::combineOperators() } else if ((tok->op == '<' || tok->op == '>') && tok->op == tok->next->op) { tok->setstr(tok->str() + tok->next->str()); deleteToken(tok->next); - if (tok->next && tok->next->op == '=') { + if (tok->next && tok->next->op == '=' && tok->next->next && tok->next->next->op != '=') { tok->setstr(tok->str() + tok->next->str()); deleteToken(tok->next); }