From f192ddad8b862d7ad2d80f28d265ea9f96142a3d Mon Sep 17 00:00:00 2001 From: Mate Barany Date: Thu, 17 Nov 2022 13:51:33 +0100 Subject: [PATCH] QString: overload prepend with QUtf8StringView Add the missing overload. [ChangeLog][QtCore][QString] Added prepend(QUtf8StringView) overload. Task-number: QTBUG-103302 Change-Id: I3f74e884e514ebc0b15a13b074584d8272a02f41 Reviewed-by: Marc Mutz --- src/corelib/text/qstring.cpp | 9 ++++++++- src/corelib/text/qstring.h | 1 + tests/auto/corelib/text/qstring/tst_qstring.cpp | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index f7ddb5fc8e..819086b014 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -3254,7 +3254,14 @@ QString &QString::append(QChar ch) \overload prepend() - Prepends the Latin-1 string \a str to this string. + Prepends the Latin-1 string view \a str to this string. +*/ + +/*! \fn QString &QString::prepend(QUtf8StringView str) + \since 6.5 + \overload prepend() + + Prepends the UTF-8 string view \a str to this string. */ /*! \fn QString &QString::prepend(const QChar *str, qsizetype len) diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index a6cc1cf867..573fca6481 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -701,6 +701,7 @@ public: inline QString &prepend(const QString &s) { return insert(0, s); } inline QString &prepend(QStringView v) { return prepend(v.data(), v.size()); } inline QString &prepend(QLatin1StringView s) { return insert(0, s); } + QString &prepend(QUtf8StringView s) { return insert(0, s); } inline QString &operator+=(QChar c) { return append(c); } diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index 037c3043e2..65c9e086cc 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -399,6 +399,8 @@ private slots: void prepend_qstringview_data() { prepend_data(EmptyIsNoop); } void prepend_qlatin1string() { prepend_impl(); } void prepend_qlatin1string_data() { prepend_data({EmptyIsNoop, Latin1Encoded}); } + void prepend_qutf8stringview() { prepend_impl(); } + void prepend_qutf8stringview_data() { prepend_data(EmptyIsNoop); } void prepend_qcharstar_int() { prepend_impl, QString &(QString::*)(const QChar *, qsizetype)>(); } void prepend_qcharstar_int_data() { prepend_data(EmptyIsNoop); } void prepend_qchar() { prepend_impl, QString &(QString::*)(QChar)>(); }