summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2023-01-29 11:12:12 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2023-03-15 20:25:57 +0000
commitf325bdacb6d236f419f9a8f76f60cea2b58f5fb5 (patch)
tree352d2b8b7d0351ebe4c68b70902edb9bdecf4865 /src/corelib
parent2ad63a097596c7f5fc3f165f24bfbbd7af7c5ef3 (diff)
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>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/io/qdebug.cpp16
-rw-r--r--src/corelib/io/qdebug.h2
-rw-r--r--src/corelib/io/qdir.cpp8
-rw-r--r--src/corelib/io/qipaddress.cpp6
-rw-r--r--src/corelib/io/qresource.cpp2
-rw-r--r--src/corelib/io/qurlidna.cpp4
-rw-r--r--src/corelib/kernel/qtranslator.cpp2
-rw-r--r--src/corelib/serialization/qxmlstream.cpp2
-rw-r--r--src/corelib/text/qchar.cpp2
9 files changed, 21 insertions, 23 deletions
diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp
index 16bb1402283..22f2c0ce8b1 100644
--- a/src/corelib/io/qdebug.cpp
+++ b/src/corelib/io/qdebug.cpp
@@ -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);
}
}
diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h
index d8db9a81620..a55a6ad100d 100644
--- a/src/corelib/io/qdebug.h
+++ b/src/corelib/io/qdebug.h
@@ -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(); }
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
index 2591670fb0e..3ad804b9e88 100644
--- a/src/corelib/io/qdir.cpp
+++ b/src/corelib/io/qdir.cpp
@@ -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] == '/';
};
diff --git a/src/corelib/io/qipaddress.cpp b/src/corelib/io/qipaddress.cpp
index 444a38a319d..9956f03738a 100644
--- a/src/corelib/io/qipaddress.cpp
+++ b/src/corelib/io/qipaddress.cpp
@@ -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();
diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp
index a0759bd1b5c..a3237f25bc0 100644
--- a/src/corelib/io/qresource.cpp
+++ b/src/corelib/io/qresource.cpp
@@ -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;
}
diff --git a/src/corelib/io/qurlidna.cpp b/src/corelib/io/qurlidna.cpp
index 5fc6006ef4d..620034b5265 100644
--- a/src/corelib/io/qurlidna.cpp
+++ b/src/corelib/io/qurlidna.cpp
@@ -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;
diff --git a/src/corelib/kernel/qtranslator.cpp b/src/corelib/kernel/qtranslator.cpp
index 521503b96bc..9f9575f5177 100644
--- a/src/corelib/kernel/qtranslator.cpp
+++ b/src/corelib/kernel/qtranslator.cpp
@@ -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;
}
diff --git a/src/corelib/serialization/qxmlstream.cpp b/src/corelib/serialization/qxmlstream.cpp
index e03b1a2c673..c6d085714fb 100644
--- a/src/corelib/serialization/qxmlstream.cpp
+++ b/src/corelib/serialization/qxmlstream.cpp
@@ -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) {
diff --git a/src/corelib/text/qchar.cpp b/src/corelib/text/qchar.cpp
index 272de292c5e..4175b6c8494 100644
--- a/src/corelib/text/qchar.cpp
+++ b/src/corelib/text/qchar.cpp
@@ -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