Use QtMiscUtils hex/oct-related helpers

Thanks to Thiago for pointing them out in review.

Change-Id: I14d588a8bd5ba29d43a5daeacfd55d974eb65557
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Ahmad Samir 2023-02-03 00:18:05 +02:00
parent 498f345228
commit 27db859c6a
4 changed files with 18 additions and 29 deletions

View File

@ -751,8 +751,8 @@ StNormal:
ch = str.at(i);
if (isHexDigit(ch))
goto StHexEscape;
} else if (isOctalDigit(ch)) {
escapeVal = ch - '0';
} else if (const int o = fromOct(ch); o != -1) {
escapeVal = o;
goto StOctEscape;
} else if (ch == '\n' || ch == '\r') {
if (i < str.size()) {
@ -814,11 +814,9 @@ StHexEscape:
}
ch = str.at(i);
if (ch >= 'a')
ch -= 'a' - 'A';
if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F')) {
if (const int h = fromHex(ch); h != -1) {
escapeVal <<= 4;
escapeVal += QtMiscUtils::fromHex(ch);
escapeVal += h;
++i;
goto StHexEscape;
} else {
@ -833,9 +831,9 @@ StOctEscape:
}
ch = str.at(i);
if (ch >= '0' && ch <= '7') {
if (const int o = fromOct(ch); o != -1) {
escapeVal <<= 3;
escapeVal += ch - '0';
escapeVal += o;
++i;
goto StOctEscape;
} else {

View File

@ -148,12 +148,8 @@ static inline QByteArray makePattern(const QByteArray &value)
char c = 0;
for (int i = 0; i < 2 && p + 1 < e; ++i) {
++p;
if (*p >= '0' && *p <= '9')
c = (c << 4) + *p - '0';
else if (*p >= 'a' && *p <= 'f')
c = (c << 4) + *p - 'a' + 10;
else if (*p >= 'A' && *p <= 'F')
c = (c << 4) + *p - 'A' + 10;
if (const int h = fromHex(*p); h != -1)
c = (c << 4) + h;
else
continue;
}

View File

@ -780,15 +780,13 @@ bool Parser::parseNumber()
static inline bool addHexDigit(char digit, char32_t *result)
{
*result <<= 4;
if (digit >= '0' && digit <= '9')
*result |= (digit - '0');
else if (digit >= 'a' && digit <= 'f')
*result |= (digit - 'a') + 10;
else if (digit >= 'A' && digit <= 'F')
*result |= (digit - 'A') + 10;
else
return false;
return true;
const int h = fromHex(digit);
if (h != -1) {
*result |= h;
return true;
}
return false;
}
static inline bool scanEscapeSequence(const char *&json, const char *end, char32_t *ch)

View File

@ -1752,13 +1752,10 @@ QTextStreamPrivate::NumberParsingStatus QTextStreamPrivate::getNumber(qulonglong
// Parse digits
int ndigits = 0;
while (getChar(&dig)) {
int n = dig.toLower().unicode();
if (n >= '0' && n <= '9') {
const int h = fromHex(dig.unicode());
if (h != -1) {
val <<= 4;
val += n - '0';
} else if (n >= 'a' && n <= 'f') {
val <<= 4;
val += 10 + (n - 'a');
val += h;
} else {
ungetChar(dig);
break;