Merge pull request #12740 from ethereum/remove-locale-dependent-operations

Replace all locale-dependent operations with locale-agnostic counterparts
This commit is contained in:
chriseth
2022-03-07 17:56:58 +01:00
committed by GitHub
16 changed files with 106 additions and 52 deletions
+2 -1
View File
@@ -22,6 +22,7 @@
#include <libsolutil/CommonData.h>
#include <libsolutil/CommonIO.h>
#include <libsolutil/StringUtils.h>
#include <boost/algorithm/string.hpp>
@@ -216,7 +217,7 @@ string BytesUtils::formatString(bytes const& _bytes, size_t _cutOff)
os << "\\n";
break;
default:
if (isprint(v))
if (isPrint(static_cast<char>(v)))
os << v;
else
os << "\\x" << toHex(v, HexCase::Lower);
+9 -6
View File
@@ -762,13 +762,16 @@ string TestFileParser::Scanner::scanString()
// TODO: use fromHex() from CommonData
char TestFileParser::Scanner::scanHexPart()
{
auto toLower = [](char _c) -> char { return tolower(_c, locale::classic()); };
auto isDigit = [](char _c) -> bool { return isdigit(_c, locale::classic()); };
advance(); // skip 'x'
int value{};
if (isdigit(current()))
if (isDigit(current()))
value = current() - '0';
else if (tolower(current()) >= 'a' && tolower(current()) <= 'f')
value = tolower(current()) - 'a' + 10;
else if (toLower(current()) >= 'a' && toLower(current()) <= 'f')
value = toLower(current()) - 'a' + 10;
else
BOOST_THROW_EXCEPTION(TestParserError("\\x used with no following hex digits."));
@@ -777,10 +780,10 @@ char TestFileParser::Scanner::scanHexPart()
return static_cast<char>(value);
value <<= 4;
if (isdigit(current()))
if (isDigit(current()))
value |= current() - '0';
else if (tolower(current()) >= 'a' && tolower(current()) <= 'f')
value |= tolower(current()) - 'a' + 10;
else if (toLower(current()) >= 'a' && toLower(current()) <= 'f')
value |= toLower(current()) - 'a' + 10;
advance();