Replace ushort*/uint* with char16_t*/char32_t* in private API [1]

Task-number: QTBUG-110403
Pick-to: 6.5
Change-Id: Ie20a831f22212d56659cf3c6940d17134ab5f2c5
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Ahmad Samir 2023-01-29 11:12:12 +02:00 committed by Volker Hilsheimer
parent 2ad63a0975
commit f325bdacb6
12 changed files with 25 additions and 27 deletions

View File

@ -195,10 +195,8 @@ void QDebug::putUcs4(uint ucs4)
// These two functions return true if the character should be printed by QDebug.
// For QByteArray, this is technically identical to US-ASCII isprint();
// for QString, we use QChar::isPrint, which requires a full UCS-4 decode.
static inline bool isPrintable(uint ucs4)
{ return QChar::isPrint(ucs4); }
static inline bool isPrintable(ushort uc)
{ return QChar::isPrint(uc); }
static inline bool isPrintable(char32_t ucs4) { return QChar::isPrint(ucs4); }
static inline bool isPrintable(char16_t uc) { return QChar::isPrint(uc); }
static inline bool isPrintable(uchar c)
{ return c >= ' ' && c < 0x7f; }
@ -240,7 +238,7 @@ static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, si
// print as an escape sequence (maybe, see below for surrogate pairs)
qsizetype buflen = 2;
ushort buf[sizeof "\\U12345678" - 1];
char16_t buf[std::char_traits<char>::length("\\U12345678")];
buf[0] = '\\';
switch (*p) {
@ -276,7 +274,7 @@ static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, si
if (QChar::isHighSurrogate(*p)) {
if ((p + 1) != end && QChar::isLowSurrogate(p[1])) {
// properly-paired surrogates
uint ucs4 = QChar::surrogateToUcs4(*p, p[1]);
char32_t ucs4 = QChar::surrogateToUcs4(*p, p[1]);
if (isPrintable(ucs4)) {
buf[0] = *p;
buf[1] = p[1];
@ -299,8 +297,8 @@ static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, si
// improperly-paired surrogates, fall through
}
buf[1] = 'u';
buf[2] = toHexUpper(ushort(*p) >> 12);
buf[3] = toHexUpper(ushort(*p) >> 8);
buf[2] = toHexUpper(char16_t(*p) >> 12);
buf[3] = toHexUpper(char16_t(*p) >> 8);
buf[4] = toHexUpper(*p >> 4);
buf[5] = toHexUpper(*p);
buflen = 6;
@ -325,7 +323,7 @@ void QDebug::putString(const QChar *begin, size_t length)
// we'll reset the QTextStream formatting mechanisms, so save the state
QDebugStateSaver saver(*this);
stream->ts.d_ptr->params.reset();
putEscapedString(stream->ts.d_ptr.data(), reinterpret_cast<const ushort *>(begin), length);
putEscapedString(stream->ts.d_ptr.data(), reinterpret_cast<const char16_t *>(begin), length);
}
}

View File

@ -100,7 +100,7 @@ public:
inline QDebug &operator<<(char t) { stream->ts << t; return maybeSpace(); }
inline QDebug &operator<<(signed short t) { stream->ts << t; return maybeSpace(); }
inline QDebug &operator<<(unsigned short t) { stream->ts << t; return maybeSpace(); }
inline QDebug &operator<<(char16_t t) { return *this << QChar(ushort(t)); }
inline QDebug &operator<<(char16_t t) { return *this << QChar(t); }
inline QDebug &operator<<(char32_t t) { putUcs4(t); return maybeSpace(); }
inline QDebug &operator<<(signed int t) { stream->ts << t; return maybeSpace(); }
inline QDebug &operator<<(unsigned int t) { stream->ts << t; return maybeSpace(); }

View File

@ -2217,8 +2217,8 @@ QString qt_normalizePathSegments(const QString &name, QDirPrivate::PathNormaliza
QVarLengthArray<char16_t> outVector(len);
qsizetype used = len;
char16_t *out = outVector.data();
const ushort *p = reinterpret_cast<const ushort *>(name.data());
const ushort *prefix = p;
const char16_t *p = reinterpret_cast<const char16_t *>(name.data());
const char16_t *prefix = p;
qsizetype up = 0;
const qsizetype prefixLength = rootLength(name, allowUncPaths);
@ -2232,10 +2232,10 @@ QString qt_normalizePathSegments(const QString &name, QDirPrivate::PathNormaliza
--i;
}
auto isDot = [](const ushort *p, qsizetype i) {
auto isDot = [](const char16_t *p, qsizetype i) {
return i > 1 && p[i - 1] == '.' && p[i - 2] == '/';
};
auto isDotDot = [](const ushort *p, qsizetype i) {
auto isDotDot = [](const char16_t *p, qsizetype i) {
return i > 2 && p[i - 1] == '.' && p[i - 2] == '.' && p[i - 3] == '/';
};

View File

@ -22,9 +22,9 @@ static QString number(quint8 val)
typedef QVarLengthArray<char, 64> Buffer;
static const QChar *checkedToAscii(Buffer &buffer, const QChar *begin, const QChar *end)
{
const ushort *const ubegin = reinterpret_cast<const ushort *>(begin);
const ushort *const uend = reinterpret_cast<const ushort *>(end);
const ushort *src = ubegin;
const auto *const ubegin = reinterpret_cast<const char16_t *>(begin);
const auto *const uend = reinterpret_cast<const char16_t *>(end);
auto *src = ubegin;
buffer.resize(uend - ubegin + 1);
char *dst = buffer.data();

View File

@ -753,7 +753,7 @@ inline QString QResourceRoot::name(int node) const
ret.resize(name_length);
QChar *strData = ret.data();
qFromBigEndian<ushort>(names + name_offset, name_length, strData);
qFromBigEndian<char16_t>(names + name_offset, name_length, strData);
return ret;
}

View File

@ -320,8 +320,8 @@ Q_CONSTINIT static QStringList *user_idn_whitelist = nullptr;
static bool lessThan(const QChar *a, int l, const char *c)
{
const ushort *uc = (const ushort *)a;
const ushort *e = uc + l;
const auto *uc = reinterpret_cast<const char16_t *>(a);
const char16_t *e = uc + l;
if (!c || *c == 0)
return false;

View File

@ -914,7 +914,7 @@ end:
if (!tn)
return QString();
QString str(tn_length / 2, Qt::Uninitialized);
qFromBigEndian<ushort>(tn, str.size(), str.data());
qFromBigEndian<char16_t>(tn, str.size(), str.data());
return str;
}

View File

@ -1721,7 +1721,7 @@ void QXmlStreamReaderPrivate::checkPublicLiteral(QStringView publicId)
{
//#x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
const ushort *data = reinterpret_cast<const ushort *>(publicId.constData());
const char16_t *data = publicId.utf16();
uchar c = 0;
qsizetype i;
for (i = publicId.size() - 1; i >= 0; --i) {

View File

@ -2060,7 +2060,7 @@ static bool normalizationQuickCheckHelper(QString *str, QString::NormalizationFo
enum { NFQC_YES = 0, NFQC_NO = 1, NFQC_MAYBE = 3 };
const ushort *string = reinterpret_cast<const ushort *>(str->constData());
const auto *string = reinterpret_cast<const char16_t *>(str->constData());
qsizetype length = str->size();
// this avoids one out of bounds check in the loop

View File

@ -1603,8 +1603,8 @@ public:
return nodeName == "QToolTip"_L1;
#endif
do {
const ushort *uc = (const ushort *)nodeName.constData();
const ushort *e = uc + nodeName.size();
const auto *uc = reinterpret_cast<const char16_t *>(nodeName.constData());
const auto *e = uc + nodeName.size();
const uchar *c = (const uchar *)metaObject->className();
while (*c && uc != e && (*uc == *c || (*c == ':' && *uc == '-'))) {
++uc;

View File

@ -2018,7 +2018,7 @@ void tst_Collections::qstring()
s = "ascii";
s += QChar((uchar) 0xb0);
QVERIFY(s.toUtf8() != s.toLatin1());
QCOMPARE(s[s.size()-1].unicode(), (ushort)0xb0);
QCOMPARE(s[s.size()-1].unicode(), char16_t(0xb0));
QCOMPARE(s.left(s.size()-1), QLatin1String("ascii"));
QVERIFY(s == QString::fromUtf8(s.toUtf8().constData()));

View File

@ -42,7 +42,7 @@ size_t qHash(const Qt50String &key, size_t seed)
// (for instance, gcc 4.4 does that even at -O0).
size_t qHash(const JavaString &str)
{
const unsigned short *p = (unsigned short *)str.constData();
const auto *p = reinterpret_cast<const char16_t *>(str.constData());
const qsizetype len = str.size();
uint h = 0;