From 0a24e2e984afdbb44c5462038fa6059dc73520d8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 4 Feb 2022 14:50:36 +0100 Subject: [PATCH] QSettings: use QtMiscUtils hex tools instead of rolling your own Removes a static string literal. QtMiscUtils allows the compiler to possibly avoid the array, or share with other TUs Pick-to: 6.3 Change-Id: I449800f113620a53d2f4b11fe027ebcb710f7b86 Reviewed-by: Thiago Macieira --- src/corelib/io/qsettings.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index e72b4349c8..1d6f2dc912 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -48,6 +48,7 @@ #include "qfileinfo.h" #include "qmutex.h" #include "private/qlocking_p.h" +#include "private/qtools_p.h" #include "qlibraryinfo.h" #include "qtemporaryfile.h" #include "qstandardpaths.h" @@ -515,8 +516,6 @@ QVariant QSettingsPrivate::stringToVariant(const QString &s) return QVariant(s); } -static const char hexDigits[] = "0123456789ABCDEF"; - void QSettingsPrivate::iniEscapedKey(const QString &key, QByteArray &result) { result.reserve(result.length() + key.length() * 3 / 2); @@ -530,13 +529,13 @@ void QSettingsPrivate::iniEscapedKey(const QString &key, QByteArray &result) result += (char)ch; } else if (ch <= 0xFF) { result += '%'; - result += hexDigits[ch / 16]; - result += hexDigits[ch % 16]; + result += QtMiscUtils::toHexUpper(ch / 16); + result += QtMiscUtils::toHexUpper(ch % 16); } else { result += "%U"; QByteArray hexCode; for (int i = 0; i < 4; ++i) { - hexCode.prepend(hexDigits[ch % 16]); + hexCode.prepend(QtMiscUtils::toHexUpper(ch % 16)); ch >>= 4; } result += hexCode; @@ -834,7 +833,7 @@ StHexEscape: ch -= 'a' - 'A'; if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F')) { escapeVal <<= 4; - escapeVal += strchr(hexDigits, ch) - hexDigits; + escapeVal += QtMiscUtils::fromHex(ch); ++i; goto StHexEscape; } else {