diff options
-rw-r--r-- | src/corelib/plugin/quuid.cpp | 12 | ||||
-rw-r--r-- | src/corelib/tools/qbytearray.cpp | 12 | ||||
-rw-r--r-- | src/corelib/tools/qtools_p.h | 11 |
3 files changed, 17 insertions, 18 deletions
diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp index f7c569f123..6df3f3b0d1 100644 --- a/src/corelib/plugin/quuid.cpp +++ b/src/corelib/plugin/quuid.cpp @@ -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; diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index bf29ebcd6d..92c2188caa 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -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; diff --git a/src/corelib/tools/qtools_p.h b/src/corelib/tools/qtools_p.h index 2acf3427f0..53d5228c3b 100644 --- a/src/corelib/tools/qtools_p.h +++ b/src/corelib/tools/qtools_p.h @@ -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. |