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>
This commit is contained in:
Thiago Macieira 2025-02-14 08:50:10 -08:00 committed by Marc Mutz
parent ba18ae3869
commit 4b278fd998
3 changed files with 14 additions and 3 deletions

View File

@ -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]

View File

@ -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));

View File

@ -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)