summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorAnton Kudryavtsev <anton.kudryavtsev@corp.mail.ru>2018-01-31 20:26:38 +0300
committerAnton Kudryavtsev <antkudr@mail.ru>2018-02-02 14:49:15 +0000
commit0c0ee82bff31ff2733c5229cf39f678f80b2e7e6 (patch)
treee88e0d623d39b2095d41d6b5381335fad4e2073f /src/corelib/tools
parent5c60e4b8f9cc88e48f5e7652eefe90e1366ae23d (diff)
QString:: add remove() overload taking QLatin1String
[ChangeLog][QtCore][QString] Added remove() overload taking QLatin1String Change-Id: I11ddb8b8603144effe44f89d0d02e131a255122c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qstring.cpp46
-rw-r--r--src/corelib/tools/qstring.h1
2 files changed, 37 insertions, 10 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index 4e7baa18b6..4040d59b0a 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -2586,6 +2586,21 @@ QString &QString::remove(int pos, int len)
return *this;
}
+template<typename T>
+static void removeStringImpl(QString &s, const T &needle, Qt::CaseSensitivity cs)
+{
+ const int needleSize = needle.size();
+ if (needleSize) {
+ if (needleSize == 1) {
+ s.remove(needle.front(), cs);
+ } else {
+ int i = 0;
+ while ((i = s.indexOf(needle, i, cs)) != -1)
+ s.remove(i, needleSize);
+ }
+ }
+}
+
/*!
Removes every occurrence of the given \a str string in this
string, and returns a reference to this string.
@@ -2599,16 +2614,27 @@ QString &QString::remove(int pos, int len)
*/
QString &QString::remove(const QString &str, Qt::CaseSensitivity cs)
{
- const int strSize = str.size();
- if (strSize) {
- if (strSize == 1) {
- remove(str.front(), cs);
- } else {
- int i = 0;
- while ((i = indexOf(str, i, cs)) != -1)
- remove(i, strSize);
- }
- }
+ removeStringImpl(*this, str, cs);
+ return *this;
+}
+
+/*!
+ \since 5.11
+ \overload
+
+ Removes every occurrence of the given \a str string in this
+ string, and returns a reference to this string.
+
+ If \a cs is Qt::CaseSensitive (default), the search is
+ case sensitive; otherwise the search is case insensitive.
+
+ This is the same as \c replace(str, "", cs).
+
+ \sa replace()
+*/
+QString &QString::remove(QLatin1String str, Qt::CaseSensitivity cs)
+{
+ removeStringImpl(*this, str, cs);
return *this;
}
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index b40a622c7c..0138ae4098 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -483,6 +483,7 @@ public:
QString &remove(int i, int len);
QString &remove(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive);
+ QString &remove(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive);
QString &remove(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive);
QString &replace(int i, int len, QChar after);
QString &replace(int i, int len, const QChar *s, int slen);