Merge the multiple implementations of fromHex too

Change-Id: I8c22f784207dd8bffb88e70ac3c867abf0af86af
Reviewed-by: Jason McDonald <macadder1@gmail.com>
This commit is contained in:
Thiago Macieira 2014-11-18 14:19:09 -08:00
parent cfe12f716b
commit ef89efe137
3 changed files with 17 additions and 18 deletions

View File

@ -62,15 +62,9 @@ bool _q_fromHex(const Char *&src, Integral &value)
value = 0;
for (uint i = 0; i < sizeof(Integral) * 2; ++i) {
int ch = *src++;
int tmp;
if (ch >= '0' && ch <= '9')
tmp = ch - '0';
else if (ch >= 'a' && ch <= 'f')
tmp = ch - 'a' + 10;
else if (ch >= 'A' && ch <= 'F')
tmp = ch - 'A' + 10;
else
uint ch = *src++;
int tmp = QtMiscUtils::fromHex(ch);
if (tmp == -1)
return false;
value = value * 16 + tmp;

View File

@ -4125,15 +4125,9 @@ QByteArray QByteArray::fromHex(const QByteArray &hexEncoded)
bool odd_digit = true;
for (int i = hexEncoded.size() - 1; i >= 0; --i) {
int ch = hexEncoded.at(i);
int tmp;
if (ch >= '0' && ch <= '9')
tmp = ch - '0';
else if (ch >= 'a' && ch <= 'f')
tmp = ch - 'a' + 10;
else if (ch >= 'A' && ch <= 'F')
tmp = ch - 'A' + 10;
else
uchar ch = uchar(hexEncoded.at(i));
int tmp = QtMiscUtils::fromHex(ch);
if (tmp == -1)
continue;
if (odd_digit) {
--result;

View File

@ -62,6 +62,17 @@ inline char toHexLower(uint value)
static const char hexdigits[] = "0123456789abcdef";
return hexdigits[value & 0xF];
}
inline int fromHex(uint c)
{
if ((c >= '0') && (c <= '9'))
return c - '0';
if ((c >= 'A') && (c <= 'F'))
return c - 'A' + 10;
if ((c >= 'a') && (c <= 'f'))
return c - 'a' + 10;
return -1;
}
}
// We typically need an extra bit for qNextPowerOfTwo when determining the next allocation size.