summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/io/qsettings.cpp13
-rw-r--r--src/corelib/io/qurl.cpp24
-rw-r--r--src/corelib/kernel/qmetaobject_p.h9
-rw-r--r--src/corelib/mimetypes/qmimemagicrule.cpp8
-rw-r--r--src/corelib/serialization/qjsonparser.cpp9
-rw-r--r--src/corelib/serialization/qtextstream.cpp4
-rw-r--r--src/corelib/serialization/qxmlstream.cpp6
-rw-r--r--src/corelib/serialization/qxmlutils.cpp18
-rw-r--r--src/corelib/text/qlocale.cpp13
-rw-r--r--src/corelib/text/qlocale_tools.cpp5
-rw-r--r--src/corelib/text/qstring.cpp42
-rw-r--r--src/corelib/text/qstringconverter.cpp13
-rw-r--r--src/corelib/time/qtimezoneprivate.cpp9
-rw-r--r--src/corelib/tools/qtools_p.h40
-rw-r--r--src/dbus/qdbusutil.cpp14
-rw-r--r--src/gui/image/qxbmhandler.cpp12
-rw-r--r--src/gui/image/qxpmhandler.cpp13
-rw-r--r--src/network/access/qnetworkreplyhttpimpl.cpp6
-rw-r--r--src/plugins/tls/shared/qasn1element.cpp8
19 files changed, 136 insertions, 130 deletions
diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp
index 48c8079ee8..f9256e3124 100644
--- a/src/corelib/io/qsettings.cpp
+++ b/src/corelib/io/qsettings.cpp
@@ -66,6 +66,7 @@
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
+using namespace QtMiscUtils;
struct QConfFileCustomFormat
{
@@ -513,8 +514,7 @@ void QSettingsPrivate::iniEscapedKey(const QString &key, QByteArray &result)
if (ch == '/') {
result += '\\';
- } else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9')
- || ch == '_' || ch == '-' || ch == '.') {
+ } else if (isAsciiLetterOrNumber(ch) || ch == '_' || ch == '-' || ch == '.') {
result += (char)ch;
} else if (ch <= 0xFF) {
result += '%';
@@ -606,10 +606,7 @@ void QSettingsPrivate::iniEscapedString(const QString &str, QByteArray &result)
if (ch == ';' || ch == ',' || ch == '=')
needsQuotes = true;
- if (escapeNextIfDigit
- && ((ch >= '0' && ch <= '9')
- || (ch >= 'a' && ch <= 'f')
- || (ch >= 'A' && ch <= 'F'))) {
+ if (escapeNextIfDigit && isHexDigit(ch)) {
result += "\\x" + QByteArray::number(ch, 16);
continue;
}
@@ -752,9 +749,9 @@ StNormal:
goto end;
ch = str.at(i);
- if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f'))
+ if (isHexDigit(ch))
goto StHexEscape;
- } else if (ch >= '0' && ch <= '7') {
+ } else if (isOctalDigit(ch)) {
escapeVal = ch - '0';
goto StOctEscape;
} else if (ch == '\n' || ch == '\r') {
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 0d42a78422..b6f4d00c15 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -402,15 +402,17 @@
#include "private/qipaddress_p.h"
#include "qurlquery.h"
#include "private/qdir_p.h"
+#include <private/qtools_p.h>
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
+using namespace QtMiscUtils;
inline static bool isHex(char c)
{
c |= 0x20;
- return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f');
+ return isAsciiDigit(c) || (c >= 'a' && c <= 'f');
}
static inline QString ftpScheme()
@@ -961,14 +963,14 @@ inline bool QUrlPrivate::setScheme(const QString &value, qsizetype len, bool doS
qsizetype needsLowercasing = -1;
const ushort *p = reinterpret_cast<const ushort *>(value.data());
for (qsizetype i = 0; i < len; ++i) {
- if (p[i] >= 'a' && p[i] <= 'z')
+ if (isAsciiLower(p[i]))
continue;
- if (p[i] >= 'A' && p[i] <= 'Z') {
+ if (isAsciiUpper(p[i])) {
needsLowercasing = i;
continue;
}
if (i) {
- if (p[i] >= '0' && p[i] <= '9')
+ if (isAsciiDigit(p[i]))
continue;
if (p[i] == '+' || p[i] == '-' || p[i] == '.')
continue;
@@ -989,7 +991,7 @@ inline bool QUrlPrivate::setScheme(const QString &value, qsizetype len, bool doS
QChar *schemeData = scheme.data(); // force detaching here
for (qsizetype i = needsLowercasing; i >= 0; --i) {
ushort c = schemeData[i].unicode();
- if (c >= 'A' && c <= 'Z')
+ if (isAsciiUpper(c))
schemeData[i] = QChar(c + 0x20);
}
}
@@ -1041,7 +1043,7 @@ inline void QUrlPrivate::setAuthority(const QString &auth, qsizetype from, qsize
unsigned long x = 0;
for (qsizetype i = colonIndex + 1; i < end; ++i) {
ushort c = auth.at(i).unicode();
- if (c >= '0' && c <= '9') {
+ if (isAsciiDigit(c)) {
x *= 10;
x += c - '0';
} else {
@@ -1183,9 +1185,7 @@ static const QChar *parseIpFuture(QString &host, const QChar *begin, const QChar
const QChar *const origBegin = begin;
if (begin[3].unicode() != '.')
return &begin[3];
- if ((begin[2].unicode() >= 'A' && begin[2].unicode() <= 'F') ||
- (begin[2].unicode() >= 'a' && begin[2].unicode() <= 'f') ||
- (begin[2].unicode() >= '0' && begin[2].unicode() <= '9')) {
+ if (isHexDigit(begin[2].unicode())) {
// this is so unlikely that we'll just go down the slow path
// decode the whole string, skipping the "[vH." and "]" which we already know to be there
host += QStringView(begin, 4);
@@ -1204,11 +1204,7 @@ static const QChar *parseIpFuture(QString &host, const QChar *begin, const QChar
}
for ( ; begin != end; ++begin) {
- if (begin->unicode() >= 'A' && begin->unicode() <= 'Z')
- host += *begin;
- else if (begin->unicode() >= 'a' && begin->unicode() <= 'z')
- host += *begin;
- else if (begin->unicode() >= '0' && begin->unicode() <= '9')
+ if (isAsciiLetterOrNumber(begin->unicode()))
host += *begin;
else if (begin->unicode() < 0x80 && strchr(acceptable, begin->unicode()) != nullptr)
host += *begin;
diff --git a/src/corelib/kernel/qmetaobject_p.h b/src/corelib/kernel/qmetaobject_p.h
index c93a82196e..d05b727f52 100644
--- a/src/corelib/kernel/qmetaobject_p.h
+++ b/src/corelib/kernel/qmetaobject_p.h
@@ -23,11 +23,14 @@
#ifndef QT_NO_QOBJECT
#include <private/qobject_p.h> // For QObjectPrivate::Connection
#endif
+#include <private/qtools_p.h>
#include <QtCore/qvarlengtharray.h>
QT_BEGIN_NAMESPACE
// ### TODO - QTBUG-87869: wrap in a proper Q_NAMESPACE and use scoped enums, to avoid name clashes
+using namespace QtMiscUtils;
+
enum PropertyFlags {
Invalid = 0x00000000,
Readable = 0x00000001,
@@ -265,11 +268,7 @@ enum { MetaObjectPrivateFieldCount = sizeof(QMetaObjectPrivate) / sizeof(int) };
// mirrored in moc's utils.h
static inline bool is_ident_char(char s)
{
- return ((s >= 'a' && s <= 'z')
- || (s >= 'A' && s <= 'Z')
- || (s >= '0' && s <= '9')
- || s == '_'
- );
+ return isAsciiLetterOrNumber(s) || s == '_';
}
static inline bool is_space(char s)
diff --git a/src/corelib/mimetypes/qmimemagicrule.cpp b/src/corelib/mimetypes/qmimemagicrule.cpp
index b1019afc84..b6f2c9af20 100644
--- a/src/corelib/mimetypes/qmimemagicrule.cpp
+++ b/src/corelib/mimetypes/qmimemagicrule.cpp
@@ -13,10 +13,12 @@
#include <qendian.h>
#include <private/qoffsetstringarray_p.h>
+#include <private/qtools_p.h>
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
+using namespace QtMiscUtils;
// in the same order as Type!
static constexpr auto magicRuleTypes = qOffsetStringArray(
@@ -156,11 +158,11 @@ static inline QByteArray makePattern(const QByteArray &value)
continue;
}
*data++ = c;
- } else if (*p >= '0' && *p <= '7') { // oct (\\7, or \\77, or \\377)
+ } else if (isOctalDigit(*p)) { // oct (\\7, or \\77, or \\377)
char c = *p - '0';
- if (p + 1 < e && p[1] >= '0' && p[1] <= '7') {
+ if (p + 1 < e && isOctalDigit(p[1])) {
c = (c << 3) + *(++p) - '0';
- if (p + 1 < e && p[1] >= '0' && p[1] <= '7' && p[-1] <= '3')
+ if (p + 1 < e && isOctalDigit(p[1]) && p[-1] <= '3')
c = (c << 3) + *(++p) - '0';
}
*data++ = c;
diff --git a/src/corelib/serialization/qjsonparser.cpp b/src/corelib/serialization/qjsonparser.cpp
index b11ae3a9d2..d39d766d75 100644
--- a/src/corelib/serialization/qjsonparser.cpp
+++ b/src/corelib/serialization/qjsonparser.cpp
@@ -11,6 +11,7 @@
#include "private/qstringconverter_p.h"
#include "private/qcborvalue_p.h"
#include "private/qnumeric_p.h"
+#include <private/qtools_p.h>
//#define PARSER_DEBUG
#ifdef PARSER_DEBUG
@@ -28,6 +29,8 @@ static const int nestingLimit = 1024;
QT_BEGIN_NAMESPACE
+using namespace QtMiscUtils;
+
// error strings for the JSON parser
#define JSONERR_OK QT_TRANSLATE_NOOP("QJsonParseError", "no error occurred")
#define JSONERR_UNTERM_OBJ QT_TRANSLATE_NOOP("QJsonParseError", "unterminated object")
@@ -693,14 +696,14 @@ bool Parser::parseNumber()
if (json < end && *json == '0') {
++json;
} else {
- while (json < end && *json >= '0' && *json <= '9')
+ while (json < end && isAsciiDigit(*json))
++json;
}
// frac = decimal-point 1*DIGIT
if (json < end && *json == '.') {
++json;
- while (json < end && *json >= '0' && *json <= '9') {
+ while (json < end && isAsciiDigit(*json)) {
isInt = isInt && *json == '0';
++json;
}
@@ -712,7 +715,7 @@ bool Parser::parseNumber()
++json;
if (json < end && (*json == '-' || *json == '+'))
++json;
- while (json < end && *json >= '0' && *json <= '9')
+ while (json < end && isAsciiDigit(*json))
++json;
}
diff --git a/src/corelib/serialization/qtextstream.cpp b/src/corelib/serialization/qtextstream.cpp
index 83e97c834d..806616aaf4 100644
--- a/src/corelib/serialization/qtextstream.cpp
+++ b/src/corelib/serialization/qtextstream.cpp
@@ -196,6 +196,7 @@ static const int QTEXTSTREAM_BUFFERSIZE = 16384;
#include "qnumeric.h"
#include "qvarlengtharray.h"
#include <private/qdebug_p.h>
+#include <private/qtools_p.h>
#include <locale.h>
#include "private/qlocale_p.h"
@@ -245,6 +246,7 @@ static const int QTEXTSTREAM_BUFFERSIZE = 16384;
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
+using namespace QtMiscUtils;
//-------------------------------------------------------------------
@@ -1686,7 +1688,7 @@ QTextStreamPrivate::NumberParsingStatus QTextStreamPrivate::getNumber(qulonglong
int ndigits = 0;
while (getChar(&dig)) {
int n = dig.toLower().unicode();
- if (n >= '0' && n <= '7') {
+ if (isOctalDigit(n)) {
val *= 8;
val += n - '0';
} else {
diff --git a/src/corelib/serialization/qxmlstream.cpp b/src/corelib/serialization/qxmlstream.cpp
index 82212a5409..e1c0e55eb4 100644
--- a/src/corelib/serialization/qxmlstream.cpp
+++ b/src/corelib/serialization/qxmlstream.cpp
@@ -16,6 +16,7 @@
#include <qcoreapplication.h>
#include <private/qoffsetstringarray_p.h>
+#include <private/qtools_p.h>
#include <iterator>
#include "qxmlstream_p.h"
@@ -26,6 +27,7 @@ QT_BEGIN_NAMESPACE
using namespace QtPrivate;
using namespace Qt::StringLiterals;
+using namespace QtMiscUtils;
enum { StreamEOF = ~0U };
@@ -1731,9 +1733,7 @@ void QXmlStreamReaderPrivate::checkPublicLiteral(QStringView publicId)
case '$': case '_': case '%': case '\'': case '\"':
continue;
default:
- if ((c >= 'a' && c <= 'z')
- || (c >= 'A' && c <= 'Z')
- || (c >= '0' && c <= '9'))
+ if (isAsciiLetterOrNumber(c))
continue;
}
break;
diff --git a/src/corelib/serialization/qxmlutils.cpp b/src/corelib/serialization/qxmlutils.cpp
index 778e8de72d..00a1121280 100644
--- a/src/corelib/serialization/qxmlutils.cpp
+++ b/src/corelib/serialization/qxmlutils.cpp
@@ -5,8 +5,12 @@
#include "qxmlutils_p.h"
+#include <private/qtools_p.h>
+
QT_BEGIN_NAMESPACE
+using namespace QtMiscUtils;
+
/* TODO:
* - isNameChar() doesn't have to be public, it's only needed in
* qdom.cpp -- refactor fixedXmlName() to use isNCName()
@@ -197,16 +201,12 @@ bool QXmlUtils::isEncName(QStringView encName)
if (encName.isEmpty())
return false;
const auto first = encName.front().unicode();
- if (!((first >= 'a' && first <= 'z') || (first >= 'A' && first <= 'Z')))
+ if (!(isAsciiLower(first) || isAsciiUpper(first)))
return false;
for (QChar ch : encName.mid(1)) {
const auto cp = ch.unicode();
- if ((cp >= 'a' && cp <= 'z')
- || (cp >= 'A' && cp <= 'Z')
- || (cp >= '0' && cp <= '9')
- || cp == '.' || cp == '_' || cp == '-') {
+ if (isAsciiLetterOrNumber(cp) || cp == '.' || cp == '_' || cp == '-')
continue;
- }
return false;
}
return true;
@@ -285,12 +285,8 @@ bool QXmlUtils::isPublicID(QStringView candidate)
for (QChar ch : candidate) {
const ushort cp = ch.unicode();
- if ((cp >= 'a' && cp <= 'z')
- || (cp >= 'A' && cp <= 'Z')
- || (cp >= '0' && cp <= '9'))
- {
+ if (isAsciiLetterOrNumber(cp))
continue;
- }
switch (cp)
{
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp
index 7392c50d50..0714434d2d 100644
--- a/src/corelib/text/qlocale.cpp
+++ b/src/corelib/text/qlocale.cpp
@@ -22,6 +22,7 @@ QT_WARNING_DISABLE_GCC("-Wfree-nonheap-object") // false positive tracking
#include "qlocale.h"
#include "qlocale_p.h"
#include "qlocale_tools_p.h"
+#include <private/qtools_p.h>
#if QT_CONFIG(datetimeparser)
#include "private/qdatetimeparser_p.h"
#endif
@@ -60,6 +61,7 @@ QT_IMPL_METATYPE_EXTERN_TAGGED(QSystemLocale::CurrencyToStringArgument,
#endif
using namespace Qt::StringLiterals;
+using namespace QtMiscUtils;
#ifndef QT_NO_SYSTEMLOCALE
Q_CONSTINIT static QSystemLocale *_systemLocale = nullptr;
@@ -542,7 +544,7 @@ static bool validTag(QStringView tag)
// Is tag is a non-empty sequence of ASCII letters and/or digits ?
for (QChar uc : tag) {
const char16_t ch = uc.unicode();
- if (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9')))
+ if (!isAsciiLetterOrNumber(ch))
return false;
}
return tag.size() > 0;
@@ -2603,11 +2605,6 @@ QString QLocale::exponential() const
return d->m_data->exponentSeparator();
}
-static bool qIsUpper(char c)
-{
- return c >= 'A' && c <= 'Z';
-}
-
/*!
\overload
Returns a string representing the floating-point number \a f.
@@ -2645,7 +2642,7 @@ static bool qIsUpper(char c)
QString QLocale::toString(double f, char format, int precision) const
{
QLocaleData::DoubleForm form = QLocaleData::DFDecimal;
- uint flags = qIsUpper(format) ? QLocaleData::CapitalEorX : 0;
+ uint flags = isAsciiUpper(format) ? QLocaleData::CapitalEorX : 0;
switch (QtMiscUtils::toAsciiLower(format)) {
case 'f':
@@ -3983,7 +3980,7 @@ bool QLocaleData::validateChars(QStringView str, NumberMode numMode, QByteArray
const QStringView in = str.mid(i, str.at(i).isHighSurrogate() ? 2 : 1);
char c = numericToCLocale(in);
- if (c >= '0' && c <= '9') {
+ if (isAsciiDigit(c)) {
switch (state) {
case Whole:
// Nothing special to do (unless we want to check grouping sizes).
diff --git a/src/corelib/text/qlocale_tools.cpp b/src/corelib/text/qlocale_tools.cpp
index 53e70ac984..08846e0b89 100644
--- a/src/corelib/text/qlocale_tools.cpp
+++ b/src/corelib/text/qlocale_tools.cpp
@@ -7,6 +7,7 @@
#include "qlocale_p.h"
#include "qstring.h"
+#include <private/qtools_p.h>
#include <private/qnumeric_p.h>
#include <ctype.h>
@@ -37,6 +38,8 @@
QT_BEGIN_NAMESPACE
+using namespace QtMiscUtils;
+
QT_CLOCALE_HOLDER
void qt_doubleToAscii(double d, QLocaleData::DoubleForm form, int precision,
@@ -371,7 +374,7 @@ static auto scanPrefix(const char *p, const char *stop, int base)
const char *next;
int base;
};
- if (p < stop && *p >= '0' && *p <= '9') {
+ if (p < stop && isAsciiDigit(*p)) {
if (*p == '0') {
const char *x_or_b = p + 1;
if (x_or_b < stop) {
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index 12c3186a71..381ae8e6fd 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -75,6 +75,7 @@
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
+using namespace QtMiscUtils;
const char16_t QString::_empty = 0;
@@ -87,16 +88,6 @@ enum StringComparisonMode {
CompareStringsForOrdering
};
-inline bool qIsUpper(char ch)
-{
- return ch >= 'A' && ch <= 'Z';
-}
-
-inline bool qIsDigit(char ch)
-{
- return ch >= '0' && ch <= '9';
-}
-
template <typename Pointer>
char32_t foldCaseHelper(Pointer ch, Pointer start) = delete;
@@ -1361,13 +1352,6 @@ static int ucstrncmp(const char16_t *a, const char *b, size_t l)
return 0;
}
-constexpr int lencmp(qsizetype lhs, qsizetype rhs) noexcept
-{
- return lhs == rhs ? 0 :
- lhs > rhs ? 1 :
- /* else */ -1 ;
-}
-
// Unicode case-sensitive equality
template <typename Char2>
static bool ucstreq(const char16_t *a, size_t alen, const Char2 *b, size_t blen)
@@ -1391,7 +1375,7 @@ static int ucstrcmp(const char16_t *a, size_t alen, const Char2 *b, size_t blen)
}
const size_t l = qMin(alen, blen);
int cmp = ucstrncmp<CompareStringsForOrdering>(a, b, l);
- return cmp ? cmp : lencmp(alen, blen);
+ return cmp ? cmp : qt_lencmp(alen, blen);
}
using CaseInsensitiveL1 = QtPrivate::QCaseInsensitiveLatin1Hash;
@@ -1411,7 +1395,7 @@ static int latin1nicmp(const char *lhsChar, qsizetype lSize, const char *rhsChar
if (int res = CaseInsensitiveL1::difference(lhsChar[i], rhsChar[i]))
return res;
}
- return lencmp(lSize, rSize);
+ return qt_lencmp(lSize, rSize);
}
bool QtPrivate::equalStrings(QStringView lhs, QStringView rhs) noexcept
@@ -1556,12 +1540,12 @@ int QtPrivate::compareStrings(QLatin1StringView lhs, QStringView rhs, Qt::CaseSe
int QtPrivate::compareStrings(QLatin1StringView lhs, QLatin1StringView rhs, Qt::CaseSensitivity cs) noexcept
{
if (lhs.isEmpty())
- return lencmp(qsizetype(0), rhs.size());
+ return qt_lencmp(qsizetype(0), rhs.size());
if (cs == Qt::CaseInsensitive)
return latin1nicmp(lhs.data(), lhs.size(), rhs.data(), rhs.size());
const auto l = std::min(lhs.size(), rhs.size());
int r = memcmp(lhs.data(), rhs.data(), l);
- return r ? r : lencmp(lhs.size(), rhs.size());
+ return r ? r : qt_lencmp(lhs.size(), rhs.size());
}
/*!
@@ -6850,7 +6834,7 @@ static uint parse_flag_characters(const char * &c) noexcept
static int parse_field_width(const char *&c, qsizetype size)
{
- Q_ASSERT(qIsDigit(*c));
+ Q_ASSERT(isAsciiDigit(*c));
const char *const stop = c + size;
// can't be negative - started with a digit
@@ -6860,7 +6844,7 @@ static int parse_field_width(const char *&c, qsizetype size)
if (used <= 0)
return false;
// preserve Qt 5.5 behavior of consuming all digits, no matter how many
- while (c < stop && qIsDigit(*c))
+ while (c < stop && isAsciiDigit(*c))
++c;
return result < qulonglong(std::numeric_limits<int>::max()) ? int(result) : 0;
}
@@ -6950,7 +6934,7 @@ QString QString::vasprintf(const char *cformat, va_list ap)
// Parse field width
int width = -1; // -1 means unspecified
- if (qIsDigit(*c)) {
+ if (isAsciiDigit(*c)) {
width = parse_field_width(c, formatEnd - c);
} else if (*c == '*') { // can't parse this in another function, not portably, at least
width = va_arg(ap, int);
@@ -6969,7 +6953,7 @@ QString QString::vasprintf(const char *cformat, va_list ap)
if (*c == '.') {
++c;
precision = 0;
- if (qIsDigit(*c)) {
+ if (isAsciiDigit(*c)) {
precision = parse_field_width(c, formatEnd - c);
} else if (*c == '*') { // can't parse this in another function, not portably, at least
precision = va_arg(ap, int);
@@ -7030,7 +7014,7 @@ QString QString::vasprintf(const char *cformat, va_list ap)
default: u = 0; break;
}
- if (qIsUpper(*c))
+ if (isAsciiUpper(*c))
flags |= QLocaleData::CapitalEorX;
int base = 10;
@@ -7061,7 +7045,7 @@ QString QString::vasprintf(const char *cformat, va_list ap)
else
d = va_arg(ap, double);
- if (qIsUpper(*c))
+ if (isAsciiUpper(*c))
flags |= QLocaleData::CapitalEorX;
QLocaleData::DoubleForm form = QLocaleData::DFDecimal;
@@ -7707,7 +7691,7 @@ QString QString::number(double n, char format, int precision)
break;
}
- return qdtoBasicLatin(n, form, precision, qIsUpper(format));
+ return qdtoBasicLatin(n, form, precision, isAsciiUpper(format));
}
namespace {
@@ -8574,7 +8558,7 @@ QString QString::arg(double a, int fieldWidth, char format, int precision, QChar
if (fillChar == u'0')
flags |= QLocaleData::ZeroPadded;
- if (qIsUpper(format))
+ if (isAsciiUpper(format))
flags |= QLocaleData::CapitalEorX;
QLocaleData::DoubleForm form = QLocaleData::DFDecimal;
diff --git a/src/corelib/text/qstringconverter.cpp b/src/corelib/text/qstringconverter.cpp
index e25a2c7756..97072b427a 100644
--- a/src/corelib/text/qstringconverter.cpp
+++ b/src/corelib/text/qstringconverter.cpp
@@ -31,6 +31,8 @@
QT_BEGIN_NAMESPACE
+using namespace QtMiscUtils;
+
static_assert(std::is_nothrow_move_constructible_v<QStringEncoder>);
static_assert(std::is_nothrow_move_assignable_v<QStringEncoder>);
static_assert(std::is_nothrow_move_constructible_v<QStringDecoder>);
@@ -889,22 +891,15 @@ int QUtf8::compareUtf8(QByteArrayView utf8, QLatin1StringView s, Qt::CaseSensiti
return (end1 > src1) - (end2 > src2);
}
-static inline int lencmp(qsizetype lhs, qsizetype rhs) noexcept
-{
- return lhs == rhs ? 0 :
- lhs > rhs ? 1 :
- /* else */ -1 ;
-}
-
int QUtf8::compareUtf8(QByteArrayView lhs, QByteArrayView rhs, Qt::CaseSensitivity cs) noexcept
{
if (lhs.isEmpty())
- return lencmp(0, rhs.size());
+ return qt_lencmp(0, rhs.size());
if (cs == Qt::CaseSensitive) {
const auto l = std::min(lhs.size(), rhs.size());
int r = memcmp(lhs.data(), rhs.data(), l);
- return r ? r : lencmp(lhs.size(), rhs.size());
+ return r ? r : qt_lencmp(lhs.size(), rhs.size());
}
char32_t uc1 = QChar::Null;
diff --git a/src/corelib/time/qtimezoneprivate.cpp b/src/corelib/time/qtimezoneprivate.cpp
index 2dd2ca9633..43f1fea935 100644
--- a/src/corelib/time/qtimezoneprivate.cpp
+++ b/src/corelib/time/qtimezoneprivate.cpp
@@ -8,6 +8,7 @@
#include "qtimezoneprivate_data_p.h"
#include <private/qnumeric_p.h>
+#include <private/qtools_p.h>
#include <qdatastream.h>
#include <qdebug.h>
@@ -15,6 +16,8 @@
QT_BEGIN_NAMESPACE
+using namespace QtMiscUtils;
+
/*
Static utilities for looking up Windows ID tables
*/
@@ -597,12 +600,12 @@ bool QTimeZonePrivate::isValidId(const QByteArray &ianaId)
} else if (ch == '-') {
if (sectionLength == 0)
return false; // violates (4)
- } else if (!(ch >= 'a' && ch <= 'z')
- && !(ch >= 'A' && ch <= 'Z')
+ } else if (!isAsciiLower(ch)
+ && !isAsciiUpper(ch)
&& !(ch == '_')
&& !(ch == '.')
// Should ideally check these only happen as an offset:
- && !(ch >= '0' && ch <= '9')
+ && !isAsciiDigit(ch)
&& !(ch == '+')
&& !(ch == ':')) {
return false; // violates (2)
diff --git a/src/corelib/tools/qtools_p.h b/src/corelib/tools/qtools_p.h
index 3ffa553843..303e626962 100644
--- a/src/corelib/tools/qtools_p.h
+++ b/src/corelib/tools/qtools_p.h
@@ -31,6 +31,13 @@ constexpr inline char toHexLower(char32_t value) noexcept
return "0123456789abcdef"[value & 0xF];
}
+[[nodiscard]] constexpr inline int isHexDigit(char32_t c) noexcept
+{
+ return (c >= '0' && c <= '9')
+ || (c >= 'A' && c <= 'F')
+ || (c >= 'a' && c <= 'f');
+}
+
constexpr inline int fromHex(char32_t c) noexcept
{
return ((c >= '0') && (c <= '9')) ? int(c - '0') :
@@ -44,9 +51,14 @@ constexpr inline char toOct(char32_t value) noexcept
return char('0' + (value & 0x7));
}
+[[nodiscard]] constexpr inline int isOctalDigit(char32_t c) noexcept
+{
+ return c >= '0' && c <= '7';
+}
+
constexpr inline int fromOct(char32_t c) noexcept
{
- return ((c >= '0') && (c <= '7')) ? int(c - '0') : -1;
+ return isOctalDigit(c) ? int(c - '0') : -1;
}
[[nodiscard]] constexpr inline bool isAsciiDigit(char32_t c) noexcept
@@ -54,14 +66,29 @@ constexpr inline int fromOct(char32_t c) noexcept
return c >= '0' && c <= '9';
}
+constexpr inline bool isAsciiUpper(char32_t c) noexcept
+{
+ return c >= 'A' && c <= 'Z';
+}
+
+constexpr inline bool isAsciiLower(char32_t c) noexcept
+{
+ return c >= 'a' && c <= 'z';
+}
+
+constexpr inline bool isAsciiLetterOrNumber(char32_t c) noexcept
+{
+ return isAsciiDigit(c) || isAsciiLower(c) || isAsciiUpper(c);
+}
+
constexpr inline char toAsciiLower(char ch) noexcept
{
- return (ch >= 'A' && ch <= 'Z') ? ch - 'A' + 'a' : ch;
+ return isAsciiUpper(ch) ? ch - 'A' + 'a' : ch;
}
constexpr inline char toAsciiUpper(char ch) noexcept
{
- return (ch >= 'a' && ch <= 'z') ? ch - 'a' + 'A' : ch;
+ return isAsciiLower(ch) ? ch - 'a' + 'A' : ch;
}
constexpr inline int caseCompareAscii(char lhs, char rhs) noexcept
@@ -71,7 +98,12 @@ constexpr inline int caseCompareAscii(char lhs, char rhs) noexcept
return int(uchar(lhsLower)) - int(uchar(rhsLower));
}
-
+constexpr inline int qt_lencmp(qsizetype lhs, qsizetype rhs) noexcept
+{
+ return lhs == rhs ? 0 :
+ lhs > rhs ? 1 :
+ /* else */ -1 ;
+}
}
// We typically need an extra bit for qNextPowerOfTwo when determining the next allocation size.
diff --git a/src/dbus/qdbusutil.cpp b/src/dbus/qdbusutil.cpp
index eb5aab4fd6..00f05b3dd3 100644
--- a/src/dbus/qdbusutil.cpp
+++ b/src/dbus/qdbusutil.cpp
@@ -7,6 +7,7 @@
#include <QtCore/qlist.h>
#include <QtCore/qstringlist.h>
+#include <private/qtools_p.h>
#include "qdbusargument.h"
#include "qdbusunixfiledescriptor.h"
@@ -16,29 +17,24 @@
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
+using namespace QtMiscUtils;
static inline bool isValidCharacterNoDash(QChar c)
{
ushort u = c.unicode();
- return (u >= 'a' && u <= 'z')
- || (u >= 'A' && u <= 'Z')
- || (u >= '0' && u <= '9')
- || (u == '_');
+ return isAsciiLetterOrNumber(u) || (u == '_');
}
static inline bool isValidCharacter(QChar c)
{
ushort u = c.unicode();
- return (u >= 'a' && u <= 'z')
- || (u >= 'A' && u <= 'Z')
- || (u >= '0' && u <= '9')
+ return isAsciiLetterOrNumber(u)
|| (u == '_') || (u == '-');
}
static inline bool isValidNumber(QChar c)
{
- ushort u = c.unicode();
- return (u >= '0' && u <= '9');
+ return (isAsciiDigit(c.toLatin1()));
}
#ifndef QT_BOOTSTRAPPED
diff --git a/src/gui/image/qxbmhandler.cpp b/src/gui/image/qxbmhandler.cpp
index 5e81370887..8206fe3b29 100644
--- a/src/gui/image/qxbmhandler.cpp
+++ b/src/gui/image/qxbmhandler.cpp
@@ -16,6 +16,8 @@
QT_BEGIN_NAMESPACE
+using namespace QtMiscUtils;
+
Q_DECLARE_LOGGING_CATEGORY(lcImageIo)
/*****************************************************************************
@@ -54,11 +56,9 @@ static bool read_xbm_header(QIODevice *device, int& w, int& h)
}
auto parseDefine = [] (const char *buf, int len) -> int {
- auto isAsciiLetterOrNumber = [] (char ch) -> bool {
- return (ch >= '0' && ch <= '9') ||
- (ch >= 'A' && ch <= 'Z') ||
- (ch >= 'a' && ch <= 'z') ||
- ch == '_' || ch == '.';
+ auto checkChar = [] (char ch) -> bool {
+ return isAsciiLetterOrNumber(ch)
+ || ch == '_' || ch == '.';
};
auto isAsciiSpace = [] (char ch) -> bool {
return ch == ' ' || ch == '\t';
@@ -70,7 +70,7 @@ static bool read_xbm_header(QIODevice *device, int& w, int& h)
int index = defineLen;
while (buf[index] && isAsciiSpace(buf[index]))
++index;
- while (buf[index] && isAsciiLetterOrNumber(buf[index]))
+ while (buf[index] && checkChar(buf[index]))
++index;
while (buf[index] && isAsciiSpace(buf[index]))
++index;
diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp
index 650160ba46..50f9f035a6 100644
--- a/src/gui/image/qxpmhandler.cpp
+++ b/src/gui/image/qxpmhandler.cpp
@@ -15,12 +15,15 @@
#include <private/qcolor_p.h>
#include <private/qduplicatetracker_p.h> // for easier std::pmr detection
+#include <private/qtools_p.h>
#include <algorithm>
#include <array>
QT_BEGIN_NAMESPACE
+using namespace QtMiscUtils;
+
Q_DECLARE_LOGGING_CATEGORY(lcImageIo)
static quint64 xpmHash(const QString &str)
@@ -736,15 +739,13 @@ static QString fbname(const QString &fileName) // get file basename (sort of)
int i = qMax(s.lastIndexOf(u'/'), s.lastIndexOf(u'\\'));
if (i < 0)
i = 0;
- auto isAsciiLetterOrNumber = [](QChar ch) -> bool {
- return (ch.unicode() >= '0' && ch.unicode() <= '9') ||
- (ch.unicode() >= 'A' && ch.unicode() <= 'Z') ||
- (ch.unicode() >= 'a' && ch.unicode() <= 'z') ||
- ch.unicode() == '_';
+ auto checkChar = [](QChar ch) -> bool {
+ uchar uc = ch.unicode();
+ return isAsciiLetterOrNumber(uc) || uc == '_';
};
int start = -1;
for (; i < s.size(); ++i) {
- if (isAsciiLetterOrNumber(s.at(i))) {
+ if (checkChar(s.at(i))) {
start = i;
} else if (start > 0)
break;
diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp
index 9d1fad5c69..e0fc272b61 100644
--- a/src/network/access/qnetworkreplyhttpimpl.cpp
+++ b/src/network/access/qnetworkreplyhttpimpl.cpp
@@ -21,6 +21,7 @@
#include "QtCore/qcoreapplication.h"
#include <QtCore/private/qthread_p.h>
+#include <QtCore/private/qtools_p.h>
#include "qnetworkcookiejar.h"
#include "qnetconmonitor_p.h"
@@ -32,6 +33,7 @@
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
+using namespace QtMiscUtils;
class QNetworkProxy;
@@ -1720,8 +1722,8 @@ QNetworkCacheMetaData QNetworkReplyHttpImplPrivate::fetchCacheMetaData(const QNe
QByteArray v = q->rawHeader(header);
if (v.size() == 3
&& v[0] == '1'
- && v[1] >= '0' && v[1] <= '9'
- && v[2] >= '0' && v[2] <= '9')
+ && isAsciiDigit(v[1])
+ && isAsciiDigit(v[2]))
continue;
}
diff --git a/src/plugins/tls/shared/qasn1element.cpp b/src/plugins/tls/shared/qasn1element.cpp
index cbf038f569..507a3a727a 100644
--- a/src/plugins/tls/shared/qasn1element.cpp
+++ b/src/plugins/tls/shared/qasn1element.cpp
@@ -8,11 +8,14 @@
#include <QtCore/qdatetime.h>
#include <QtCore/qlist.h>
#include <QDebug>
+#include <private/qtools_p.h>
#include <limits>
QT_BEGIN_NAMESPACE
+using namespace QtMiscUtils;
+
typedef QMap<QByteArray, QByteArray> OidNameMap;
static OidNameMap createOidMap()
{
@@ -213,11 +216,6 @@ QDateTime QAsn1Element::toDateTime() const
// QDateTime::fromString is lenient and accepts +- signs in front
// of the year; but ASN.1 doesn't allow them.
- const auto isAsciiDigit = [](char c)
- {
- return c >= '0' && c <= '9';
- };
-
if (!isAsciiDigit(mValue[0]))
return result;