QtMiscUtils: add missing toAsciiUpper(), use it in moc

... 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.

Pick-to: 6.5 6.4 6.2 5.15
Task-number: QTBUG-109235
Change-Id: Iaf071ba2113b672aa0aed3da6a4e1d47fb659365
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2022-12-17 15:12:45 +01:00
parent 5a0dcda171
commit b8c2a0c18a
2 changed files with 8 additions and 2 deletions

View File

@ -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);

View File

@ -13,7 +13,8 @@
#include <qjsonobject.h>
#include <qversionnumber.h>
#include <stdio.h>
#include <ctype.h>
#include <private/qtools_p.h>
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);
}