From 81be57a99c28ee2c8d1c051e8ab70b4f9c8bf41e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 17 Dec 2022 15:12:45 +0100 Subject: [PATCH] QtMiscUtils: add missing toAsciiUpper(), use it in moc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... to make moc code locale-independent. The C toupper function is locale-dependent. Given the right locale (Türkiye, e.g.), toupper('i') is either - İ (LATIN CAPITAL LETTER I WITH DOT ABOVE; if representable) or - i (unchanged; if it isn't) Both results are wrong for the present use-case. Fix by adding QtMiscTools::toAsciiUpper(), complementing existing toAsciiLower(), and using that. It's private API, but moc.h, despite the name, is not a public header. Task-number: QTBUG-109235 Change-Id: Iaf071ba2113b672aa0aed3da6a4e1d47fb659365 Reviewed-by: Qt CI Bot Reviewed-by: Thiago Macieira (cherry picked from commit b8c2a0c18a0676595946b5543ff88492a5fc7876) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/tools/qtools_p.h | 5 +++++ src/tools/moc/moc.h | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/corelib/tools/qtools_p.h b/src/corelib/tools/qtools_p.h index 338f89d6338..2058f6349e7 100644 --- a/src/corelib/tools/qtools_p.h +++ b/src/corelib/tools/qtools_p.h @@ -54,6 +54,11 @@ constexpr inline char toAsciiLower(char ch) noexcept return (ch >= 'A' && ch <= 'Z') ? ch - 'A' + 'a' : ch; } +constexpr inline char toAsciiUpper(char ch) noexcept +{ + return (ch >= 'a' && ch <= 'z') ? ch - 'a' + 'A' : ch; +} + constexpr inline int caseCompareAscii(char lhs, char rhs) noexcept { const char lhsLower = QtMiscUtils::toAsciiLower(lhs); diff --git a/src/tools/moc/moc.h b/src/tools/moc/moc.h index 843a684bda7..af2a95c3915 100644 --- a/src/tools/moc/moc.h +++ b/src/tools/moc/moc.h @@ -13,7 +13,8 @@ #include #include #include -#include + +#include QT_BEGIN_NAMESPACE @@ -102,7 +103,7 @@ struct PropertyDef { bool stdCppSet() const { QByteArray s("set"); - s += toupper(name[0]); + s += QtMiscUtils::toAsciiUpper(name[0]); s += name.mid(1); return (s == write); }