diff options
-rw-r--r-- | src/corelib/io/qipaddress.cpp | 3 | ||||
-rw-r--r-- | src/corelib/io/qurlrecode.cpp | 4 | ||||
-rw-r--r-- | src/corelib/plugin/quuid.cpp | 9 | ||||
-rw-r--r-- | src/corelib/tools/qbytearray.cpp | 22 | ||||
-rw-r--r-- | src/corelib/tools/qtools_p.h | 14 | ||||
-rw-r--r-- | src/testlib/qtestcase.cpp | 21 |
6 files changed, 34 insertions, 39 deletions
diff --git a/src/corelib/io/qipaddress.cpp b/src/corelib/io/qipaddress.cpp index 44da22489d..d436cd2dd6 100644 --- a/src/corelib/io/qipaddress.cpp +++ b/src/corelib/io/qipaddress.cpp @@ -33,6 +33,7 @@ #include "qipaddress_p.h" #include "private/qlocale_tools_p.h" +#include "private/qtools_p.h" #include "qvarlengtharray.h" QT_BEGIN_NAMESPACE @@ -240,7 +241,7 @@ const QChar *parseIp6(IPv6Address &address, const QChar *begin, const QChar *end static inline QChar toHex(uchar c) { - return ushort(c > 9 ? c + 'a' - 0xA : c + '0'); + return QtMiscUtils::toHexLower(c); } void toString(QString &appendTo, IPv6Address address) diff --git a/src/corelib/io/qurlrecode.cpp b/src/corelib/io/qurlrecode.cpp index 9aad2a12bd..4cf471a248 100644 --- a/src/corelib/io/qurlrecode.cpp +++ b/src/corelib/io/qurlrecode.cpp @@ -33,6 +33,7 @@ #include "qurl.h" #include "private/qutfcodec_p.h" +#include "private/qtools_p.h" QT_BEGIN_NAMESPACE @@ -197,8 +198,7 @@ static inline ushort decodePercentEncoding(const ushort *input) static inline ushort encodeNibble(ushort c) { - static const uchar hexnumbers[] = "0123456789ABCDEF"; - return hexnumbers[c & 0xf]; + return ushort(QtMiscUtils::toHexUpper(c)); } static void ensureDetached(QString &result, ushort *&output, const ushort *begin, const ushort *input, const ushort *end, diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp index 4a5f4e791d..f7c569f123 100644 --- a/src/corelib/plugin/quuid.cpp +++ b/src/corelib/plugin/quuid.cpp @@ -36,14 +36,13 @@ #include "qdatastream.h" #include "qendian.h" #include "qdebug.h" +#include "private/qtools_p.h" #ifndef QT_BOOTSTRAPPED #include "qcryptographichash.h" #endif QT_BEGIN_NAMESPACE -static const char digits[] = "0123456789abcdef"; - template <class Char, class Integral> void _q_toHex(Char *&dst, Integral value) { @@ -52,10 +51,8 @@ void _q_toHex(Char *&dst, Integral value) const char* p = reinterpret_cast<const char*>(&value); for (uint i = 0; i < sizeof(Integral); ++i, dst += 2) { - uint j = (p[i] >> 4) & 0xf; - dst[0] = Char(digits[j]); - j = p[i] & 0xf; - dst[1] = Char(digits[j]); + dst[0] = Char(QtMiscUtils::toHexLower((p[i] >> 4) & 0xf)); + dst[1] = Char(QtMiscUtils::toHexLower(p[i] & 0xf)); } } diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 26bf7d047d..bf29ebcd6d 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -4161,16 +4161,8 @@ QByteArray QByteArray::toHex() const char *hexData = hex.data(); const uchar *data = (const uchar *)d->data(); for (int i = 0; i < d->size; ++i) { - int j = (data[i] >> 4) & 0xf; - if (j <= 9) - hexData[i*2] = (j + '0'); - else - hexData[i*2] = (j + 'a' - 10); - j = data[i] & 0xf; - if (j <= 9) - hexData[i*2+1] = (j + '0'); - else - hexData[i*2+1] = (j + 'a' - 10); + hexData[i*2] = QtMiscUtils::toHexLower(data[i] >> 4); + hexData[i*2+1] = QtMiscUtils::toHexLower(data[i] & 0xf); } return hex; } @@ -4365,12 +4357,6 @@ static inline bool q_strchr(const char str[], char chr) return false; } -static inline char toHexHelper(char c) -{ - static const char hexnumbers[] = "0123456789ABCDEF"; - return hexnumbers[c & 0xf]; -} - static void q_toPercentEncoding(QByteArray *ba, const char *dontEncode, const char *alsoEncode, char percent) { if (ba->isEmpty()) @@ -4403,8 +4389,8 @@ static void q_toPercentEncoding(QByteArray *ba, const char *dontEncode, const ch output = ba->data(); } output[length++] = percent; - output[length++] = toHexHelper((c & 0xf0) >> 4); - output[length++] = toHexHelper(c & 0xf); + output[length++] = QtMiscUtils::toHexUpper((c & 0xf0) >> 4); + output[length++] = QtMiscUtils::toHexUpper(c & 0xf); } } if (output) diff --git a/src/corelib/tools/qtools_p.h b/src/corelib/tools/qtools_p.h index 1e72db1d87..2acf3427f0 100644 --- a/src/corelib/tools/qtools_p.h +++ b/src/corelib/tools/qtools_p.h @@ -50,6 +50,20 @@ QT_BEGIN_NAMESPACE +namespace QtMiscUtils { +inline char toHexUpper(uint value) +{ + static const char hexdigits[] = "0123456789ABCDEF"; + return hexdigits[value & 0xF]; +} + +inline char toHexLower(uint value) +{ + static const char hexdigits[] = "0123456789abcdef"; + return hexdigits[value & 0xF]; +} +} + // We typically need an extra bit for qNextPowerOfTwo when determining the next allocation size. enum { MaxAllocSize = (1 << (std::numeric_limits<int>::digits - 1)) - 1 diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 24d563045b..61b0a13259 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -47,6 +47,7 @@ #include <QtCore/qprocess.h> #include <QtCore/qdebug.h> #include <QtCore/qlibraryinfo.h> +#include <QtCore/private/qtools_p.h> #include <QtTest/private/qtestlog_p.h> #include <QtTest/private/qtesttable_p.h> @@ -84,6 +85,8 @@ QT_BEGIN_NAMESPACE +using QtMiscUtils::toHexUpper; + /*! \namespace QTest \inmodule QtTest @@ -2060,12 +2063,6 @@ void *fetchData(QTestData *data, const char *tagName, int typeId) return data->data(idx); } -static char toHex(ushort value) -{ - static const char hexdigits[] = "0123456789ABCDEF"; - return hexdigits[value & 0xF]; -} - /*! \fn char* QTest::toHexRepresentation(const char *ba, int length) @@ -2115,9 +2112,9 @@ char *toHexRepresentation(const char *ba, int length) while (true) { const char at = ba[i]; - result[o] = toHex(at >> 4); + result[o] = toHexUpper(at >> 4); ++o; - result[o] = toHex(at); + result[o] = toHexUpper(at); ++i; ++o; @@ -2183,10 +2180,10 @@ char *toPrettyUnicode(const ushort *p, int length) break; default: *dst++ = 'u'; - *dst++ = toHex(*p >> 12); - *dst++ = toHex(*p >> 8); - *dst++ = toHex(*p >> 4); - *dst++ = toHex(*p); + *dst++ = toHexUpper(*p >> 12); + *dst++ = toHexUpper(*p >> 8); + *dst++ = toHexUpper(*p >> 4); + *dst++ = toHexUpper(*p); } } |