QString: port toUcs4_helper() to char16_t/char32_t
This gets rid of 50% of the casts required to call the function, and removes the last QtCore QStringView(ushort*) user. As a drive-by, replace an (allowed, but) fishy &str[0] with str.data(), the mutable overload of which has been available since C++17. Task-number: QTBUG-110403 Change-Id: Iad494025b61c53d991e59cc73198bb014a422a93 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
11891ae9c9
commit
01ef951c65
@ -493,3 +493,19 @@ void QXmlStreamWriter::writeStartElement(const QString &namespaceUri, const QStr
|
|||||||
// order sections alphabetically to reduce chances of merge conflicts
|
// order sections alphabetically to reduce chances of merge conflicts
|
||||||
|
|
||||||
#endif // QT_CORE_REMOVED_SINCE(6, 5)
|
#endif // QT_CORE_REMOVED_SINCE(6, 5)
|
||||||
|
|
||||||
|
#if QT_CORE_REMOVED_SINCE(6, 6)
|
||||||
|
|
||||||
|
#include "qstring.h"
|
||||||
|
|
||||||
|
qsizetype QString::toUcs4_helper(const ushort *uc, qsizetype length, uint *out)
|
||||||
|
{
|
||||||
|
return toUcs4_helper(reinterpret_cast<const char16_t *>(uc), length,
|
||||||
|
reinterpret_cast<char32_t *>(out));
|
||||||
|
}
|
||||||
|
|
||||||
|
// #include "qotherheader.h"
|
||||||
|
// // implement removed functions from qotherheader.h
|
||||||
|
// order sections alphabetically to reduce chances of merge conflicts
|
||||||
|
|
||||||
|
#endif // QT_CORE_REMOVED_SINCE(6, 6)
|
||||||
|
@ -2419,7 +2419,7 @@ void qtWarnAboutInvalidRegularExpression(const QString &pattern, const char *whe
|
|||||||
toStdU32String()
|
toStdU32String()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
qsizetype QString::toUcs4_helper(const ushort *uc, qsizetype length, uint *out)
|
qsizetype QString::toUcs4_helper(const char16_t *uc, qsizetype length, char32_t *out)
|
||||||
{
|
{
|
||||||
qsizetype count = 0;
|
qsizetype count = 0;
|
||||||
|
|
||||||
|
@ -859,7 +859,10 @@ private:
|
|||||||
static QByteArray toLatin1_helper_inplace(QString &);
|
static QByteArray toLatin1_helper_inplace(QString &);
|
||||||
static QByteArray toUtf8_helper(const QString &);
|
static QByteArray toUtf8_helper(const QString &);
|
||||||
static QByteArray toLocal8Bit_helper(const QChar *data, qsizetype size);
|
static QByteArray toLocal8Bit_helper(const QChar *data, qsizetype size);
|
||||||
static qsizetype toUcs4_helper(const ushort *uc, qsizetype length, uint *out); // ### Qt 7 char16_t
|
#if QT_CORE_REMOVED_SINCE(6, 6)
|
||||||
|
static qsizetype toUcs4_helper(const ushort *uc, qsizetype length, uint *out);
|
||||||
|
#endif
|
||||||
|
static qsizetype toUcs4_helper(const char16_t *uc, qsizetype length, char32_t *out);
|
||||||
static qlonglong toIntegral_helper(QStringView string, bool *ok, int base);
|
static qlonglong toIntegral_helper(QStringView string, bool *ok, int base);
|
||||||
static qulonglong toIntegral_helper(QStringView string, bool *ok, uint base);
|
static qulonglong toIntegral_helper(QStringView string, bool *ok, uint base);
|
||||||
void replace_helper(size_t *indices, qsizetype nIndices, qsizetype blen, const QChar *after, qsizetype alen);
|
void replace_helper(size_t *indices, qsizetype nIndices, qsizetype blen, const QChar *after, qsizetype alen);
|
||||||
@ -1031,8 +1034,7 @@ qsizetype QStringView::toWCharArray(wchar_t *array) const
|
|||||||
memcpy(array, src, sizeof(QChar) * size());
|
memcpy(array, src, sizeof(QChar) * size());
|
||||||
return size();
|
return size();
|
||||||
} else {
|
} else {
|
||||||
return QString::toUcs4_helper(reinterpret_cast<const ushort *>(data()), size(),
|
return QString::toUcs4_helper(utf16(), size(), reinterpret_cast<char32_t *>(array));
|
||||||
reinterpret_cast<uint *>(array));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1228,8 +1230,8 @@ inline QString QString::fromStdU32String(const std::u32string &s)
|
|||||||
inline std::u32string QString::toStdU32String() const
|
inline std::u32string QString::toStdU32String() const
|
||||||
{
|
{
|
||||||
std::u32string u32str(size(), char32_t(0));
|
std::u32string u32str(size(), char32_t(0));
|
||||||
qsizetype len = toUcs4_helper(reinterpret_cast<const ushort *>(constData()),
|
const qsizetype len = toUcs4_helper(reinterpret_cast<const char16_t *>(data()),
|
||||||
size(), reinterpret_cast<uint*>(&u32str[0]));
|
size(), u32str.data());
|
||||||
u32str.resize(len);
|
u32str.resize(len);
|
||||||
return u32str;
|
return u32str;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user