diff options
Diffstat (limited to 'src/corelib/text')
-rw-r--r-- | src/corelib/text/qstring.h | 14 | ||||
-rw-r--r-- | src/corelib/text/qstringview.cpp | 14 | ||||
-rw-r--r-- | src/corelib/text/qstringview.h | 2 |
3 files changed, 16 insertions, 14 deletions
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 08930f73b5..06ebb05fc7 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -1122,7 +1122,19 @@ QT_WARNING_DISABLE_INTEL(111) // "statement is unreachable" inline int QString::toWCharArray(wchar_t *array) const { - return QStringView(*this).toWCharArray(array); + return qToStringViewIgnoringNull(*this).toWCharArray(array); +} + +int QStringView::toWCharArray(wchar_t *array) const +{ + if (sizeof(wchar_t) == sizeof(QChar)) { + if (auto src = data()) + memcpy(array, src, sizeof(QChar) * size()); + return size(); + } else { + return QString::toUcs4_helper(reinterpret_cast<const ushort *>(data()), int(size()), + reinterpret_cast<uint *>(array)); + } } QT_WARNING_POP diff --git a/src/corelib/text/qstringview.cpp b/src/corelib/text/qstringview.cpp index 8442bcdf1b..89cb4b32c0 100644 --- a/src/corelib/text/qstringview.cpp +++ b/src/corelib/text/qstringview.cpp @@ -867,11 +867,12 @@ QT_BEGIN_NAMESPACE */ /*! + \fn QStringView::toWCharArray(wchar_t *array) const \since 5.14 Transcribes this string into the given \a array. - Caller is responsible for ensuring \a array is large enough to hold the + The caller is responsible for ensuring \a array is large enough to hold the \c wchar_t encoding of this string (allocating the array with the same length as the string is always sufficient). The array is encoded in UTF-16 on platforms where \c wchar_t is 2 bytes wide (e.g. Windows); otherwise (Unix @@ -885,15 +886,4 @@ QT_BEGIN_NAMESPACE \sa QString::toWCharArray() */ -int QStringView::toWCharArray(wchar_t *array) const -{ - if (sizeof(wchar_t) == sizeof(QChar)) { - memcpy(array, data(), sizeof(QChar) * size()); - return size(); - } else { - return QString::toUcs4_helper(reinterpret_cast<const ushort *>(data()), int(size()), - reinterpret_cast<uint *>(array)); - } -} - QT_END_NAMESPACE diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h index b84b2995b9..5a3acaa8c0 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -294,7 +294,7 @@ public: Q_REQUIRED_RESULT bool isRightToLeft() const noexcept { return QtPrivate::isRightToLeft(*this); } - Q_REQUIRED_RESULT Q_CORE_EXPORT int toWCharArray(wchar_t *array) const; + Q_REQUIRED_RESULT inline int toWCharArray(wchar_t *array) const; // defined in qstring.h // // STL compatibility API: |