summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-10-21 22:20:13 +0200
committerMarc Mutz <marc.mutz@kdab.com>2015-12-28 09:14:59 +0000
commit8f166ccf4081e624a8d23b21f236151c9dc38f28 (patch)
treef361878be2b3168670696d0cb07af9962b325b79 /src/corelib/tools
parent050b68241220a5b52c93e1f4cca3be5e71856357 (diff)
QString: add resize(int, QChar)
This will be used in QTextStream to speed up padding processing. [ChangeLog][QtCore][QString] Added resize(int, QChar) overload. Change-Id: Id51f8cdacb167310157100b05cacf20e9a5d2716 Reviewed-by: Topi Reiniƶ <topi.reinio@theqtcompany.com> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qstring.cpp23
-rw-r--r--src/corelib/tools/qstring.h1
2 files changed, 21 insertions, 3 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index 2f340477fc..4ffad7031a 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -1652,9 +1652,7 @@ QString::QString(QChar ch)
\snippet qstring/main.cpp 45
If you want to append a certain number of identical characters to
- the string, use \l operator+=() as follows rather than resize():
-
- \snippet qstring/main.cpp 46
+ the string, use the \l {QString::}{resize(int, QChar)} overload.
If you want to expand the string so that it reaches a certain
width and fill the new positions with a particular character, use
@@ -1694,6 +1692,25 @@ void QString::resize(int size)
}
}
+/*!
+ \overload
+ \since 5.7
+
+ Unlike \l {QString::}{resize(int)}, this overload
+ initializes the new characters to \a fillChar:
+
+ \snippet qstring/main.cpp 46
+*/
+
+void QString::resize(int size, QChar fillChar)
+{
+ const int oldSize = length();
+ resize(size);
+ const int difference = length() - oldSize;
+ if (difference > 0)
+ std::fill_n(d->begin() + oldSize, difference, fillChar.unicode());
+}
+
/*! \fn int QString::capacity() const
Returns the maximum number of characters that can be stored in
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index 75f94d7f93..9dc770d2c5 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -233,6 +233,7 @@ public:
inline int length() const;
inline bool isEmpty() const;
void resize(int size);
+ void resize(int size, QChar fillChar);
QString &fill(QChar c, int size = -1);
void truncate(int pos);