summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorMate Barany <mate.barany@qt.io>2022-11-16 15:48:53 +0100
committerMate Barany <mate.barany@qt.io>2022-12-02 16:04:11 +0100
commitf046589e1408863d954263ac941c51aa3b638948 (patch)
treeac6bb2fe9472584e705b9cdc8452f9b5c07fb1ec /src/corelib
parent2ffdb3bcddb2528c95571f7eaee270c5d56ab13d (diff)
QString: overload insert with QUtf8StringView
Overloading insert is a bit tricky since the size might change after the conversion so either the tail has to be moved twice or a temporary buffer is needed. For now, add an ineffective but simple overload as in the case of the const char *s overload, and do the performance optimization in a follow-up task (QTBUG-108546). [ChangeLog][QtCore][QString] Added insert(QUtf8StringView) overload. Task-number: QTBUG-103302 Change-Id: If01c216ff626da29abb43eb68d4de82824f3bfba Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/text/qstring.cpp20
-rw-r--r--src/corelib/text/qstring.h1
2 files changed, 20 insertions, 1 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index 326435f28f..f7ddb5fc8e 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -3001,7 +3001,7 @@ QString &QString::operator=(QChar ch)
\fn QString &QString::insert(qsizetype position, QLatin1StringView str)
\overload insert()
- Inserts the Latin-1 string \a str at the given index \a position.
+ Inserts the Latin-1 string view \a str at the given index \a position.
\include qstring.cpp string-grow-at-insertion
*/
@@ -3027,6 +3027,24 @@ QString &QString::insert(qsizetype i, QLatin1StringView str)
}
/*!
+ \fn QString &QString::insert(qsizetype position, QUtf8StringView str)
+ \overload insert()
+ \since 6.5
+
+ Inserts the UTF-8 string view \a str at the given index \a position.
+
+ \note Inserting variable-width UTF-8-encoded string data is conceptually slower
+ than inserting fixed-width string data such as UTF-16 (QStringView) or Latin-1
+ (QLatin1StringView) and should thus be used sparingly.
+
+ \include qstring.cpp string-grow-at-insertion
+*/
+QString &QString::insert(qsizetype i, QUtf8StringView s)
+{
+ return insert(i, s.toString()); // ### optimize (QTBUG-108546)
+}
+
+/*!
\fn QString& QString::insert(qsizetype position, const QChar *unicode, qsizetype size)
\overload insert()
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h
index 16ab13e1e9..a6cc1cf867 100644
--- a/src/corelib/text/qstring.h
+++ b/src/corelib/text/qstring.h
@@ -687,6 +687,7 @@ public:
inline QString &insert(qsizetype i, const QString &s) { return insert(i, s.constData(), s.size()); }
inline QString &insert(qsizetype i, QStringView v) { return insert(i, v.data(), v.size()); }
QString &insert(qsizetype i, QLatin1StringView s);
+ QString &insert(qsizetype i, QUtf8StringView s);
QString &append(QChar c);
QString &append(const QChar *uc, qsizetype len);