diff options
| author | Thiago Macieira <thiago.macieira@intel.com> | 2025-02-14 08:50:10 -0800 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2025-02-14 22:59:43 +0000 |
| commit | 4b278fd9989b5a4a1140a2af30d2852cd12e506e (patch) | |
| tree | e714334b06156a3aa2d437e4a020d005bae88a66 /src | |
| parent | ba18ae3869fd6703fbaad548d2421a82e7e675cc (diff) | |
QString: add fromRawData with a char16_t pointer
And I've updated the documentation to use char16_t too, making this the
primary (recommended) overload over the QChar one.
[ChangeLog][QtCore][QString] Added fromRawData() overload taking
char16_t* (was: only QChar*).
Change-Id: Iad8dd905a494706d72c4fffd40ded1cbf7122597
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src')
| -rw-r--r-- | src/corelib/doc/snippets/qstring/main.cpp | 5 | ||||
| -rw-r--r-- | src/corelib/text/qstring.cpp | 8 | ||||
| -rw-r--r-- | src/corelib/text/qstring.h | 4 |
3 files changed, 14 insertions, 3 deletions
diff --git a/src/corelib/doc/snippets/qstring/main.cpp b/src/corelib/doc/snippets/qstring/main.cpp index 5e3fa647dd1..578c7ae53aa 100644 --- a/src/corelib/doc/snippets/qstring/main.cpp +++ b/src/corelib/doc/snippets/qstring/main.cpp @@ -344,12 +344,11 @@ void Widget::fromRawDataFunction() { //! [22] QRegularExpression pattern("\u00A4"); - static const QChar unicode[] = { + static const char16_t unicode[] = { 0x005A, 0x007F, 0x00A4, 0x0060, 0x1009, 0x0020, 0x0020}; - qsizetype size = sizeof(unicode) / sizeof(QChar); - QString str = QString::fromRawData(unicode, size); + QString str = QString::fromRawData(unicode, std::size(unicode)); if (str.contains(pattern) { // ... //! [22] //! [23] diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index e60f7ff6554..d1f70005437 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -9378,6 +9378,9 @@ QString::iterator QString::erase(QString::const_iterator first, QString::const_i */ /*! + \fn QString QString::fromRawData(const char16_t *unicode, qsizetype size) + \since 6.10 + Constructs a QString that uses the first \a size Unicode characters in the array \a unicode. The data in \a unicode is \e not copied. The caller must be able to guarantee that \a unicode will @@ -9403,6 +9406,11 @@ QString::iterator QString::erase(QString::const_iterator first, QString::const_i \sa fromUtf16(), setRawData(), data(), constData(), nullTerminate(), nullTerminated() */ + +/*! + \fn QString QString::fromRawData(const QChar *unicode, qsizetype size) + \overload +*/ QString QString::fromRawData(const QChar *unicode, qsizetype size) { return QString(DataPointer::fromRawData(const_cast<char16_t *>(reinterpret_cast<const char16_t *>(unicode)), size)); diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 6157f1fa8ec..a4c35cc4a6d 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -782,6 +782,10 @@ public: } static QString fromUtf16(const char16_t *, qsizetype size = -1); static QString fromUcs4(const char32_t *, qsizetype size = -1); + static QString fromRawData(const char16_t *unicode, qsizetype size) + { + return QString(DataPointer(nullptr, const_cast<char16_t *>(unicode), size)); + } static QString fromRawData(const QChar *, qsizetype size); #if QT_DEPRECATED_SINCE(6, 0) |
