diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-10-25 19:02:40 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2020-04-24 10:45:09 +0000 |
commit | 3238445b270d5fb98f4008cb10a8adcc2d35165c (patch) | |
tree | 1781a4e7c3a0bd8ca9675b90ab79fb5c99b4a1cb /src/corelib/text | |
parent | d737db87349f4d3e9d5ff2cb4758d270cb8f1db7 (diff) |
QString: add append, op+=, prepend, insert taking QStringView
[ChangeLog][QtCore][QString] Now supports appending, prepending
and inserting QStringViews.
Change-Id: I7538c050c67590f27d91443eda0b94a4b80b62f2
Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/text')
-rw-r--r-- | src/corelib/text/qstring.cpp | 35 | ||||
-rw-r--r-- | src/corelib/text/qstring.h | 14 |
2 files changed, 49 insertions, 0 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 3f24665a8a..fa61b5939d 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -2501,6 +2501,19 @@ QString &QString::operator=(QChar ch) /*! + \fn QString& QString::insert(int position, QStringView str) + \since 6.0 + \overload insert() + + Inserts the string view \a str at the given index \a position and + returns a reference to this string. + + If the given \a position is greater than size(), the array is + first extended using resize(). +*/ + + +/*! \fn QString& QString::insert(int position, const char *str) \since 5.5 \overload insert() @@ -2765,6 +2778,14 @@ QString &QString::append(QChar ch) returns a reference to this string. */ +/*! \fn QString &QString::prepend(QStringView str) + \since 6.0 + \overload prepend() + + Prepends the string view \a str to the beginning of this string and + returns a reference to this string. +*/ + /*! \fn QString &QString::prepend(const QByteArray &ba) \overload prepend() @@ -5914,6 +5935,13 @@ QString& QString::fill(QChar ch, int size) Appends the string section referenced by \a str to this string. */ +/*! \fn QString &QString::operator+=(QStringView str) + \since 6.0 + \overload operator+=() + + Appends the string view \a str to this string. +*/ + /*! \fn QString &QString::operator+=(char ch) \overload operator+=() @@ -11038,6 +11066,13 @@ QStringRef QStringRef::appendTo(QString *string) const */ /*! + \fn QString &QString::append(QStringView str) + \since 6.0 + + Appends the given string view \a str to this string and returns the result. +*/ + +/*! \fn QString &QString::append(const QStringRef &reference) \since 4.4 diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index a841a0c123..f099683e28 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -537,18 +537,29 @@ public: QString &insert(int i, QChar c); QString &insert(int i, const QChar *uc, int len); +#if QT_STRINGVIEW_LEVEL < 2 inline QString &insert(int i, const QString &s) { return insert(i, s.constData(), s.length()); } inline QString &insert(int i, const QStringRef &s); +#endif + inline QString &insert(int i, QStringView v) { return insert(i, v.data(), v.length()); } QString &insert(int i, QLatin1String s); + QString &append(QChar c); QString &append(const QChar *uc, int len); +#if QT_STRINGVIEW_LEVEL < 2 QString &append(const QString &s); QString &append(const QStringRef &s); +#endif + inline QString &append(QStringView v) { return append(v.data(), v.length()); } QString &append(QLatin1String s); + inline QString &prepend(QChar c) { return insert(0, c); } inline QString &prepend(const QChar *uc, int len) { return insert(0, uc, len); } +#if QT_STRINGVIEW_LEVEL < 2 inline QString &prepend(const QString &s) { return insert(0, s); } inline QString &prepend(const QStringRef &s) { return insert(0, s); } +#endif + inline QString &prepend(QStringView v) { return prepend(v.data(), v.length()); } inline QString &prepend(QLatin1String s) { return insert(0, s); } inline QString &operator+=(QChar c) { @@ -560,8 +571,11 @@ public: } inline QString &operator+=(QChar::SpecialCharacter c) { return append(QChar(c)); } +#if QT_STRINGVIEW_LEVEL < 2 inline QString &operator+=(const QString &s) { return append(s); } inline QString &operator+=(const QStringRef &s) { return append(s); } +#endif + inline QString &operator+=(QStringView v) { return append(v); } inline QString &operator+=(QLatin1String s) { return append(s); } QString &remove(int i, int len); |