QStringBuilder Class
template <typename A, typename B> class QStringBuilderThe QStringBuilder class is a template class that provides a facility to build up QStrings and QByteArrays from smaller chunks. More...
Header: | #include <QStringBuilder> |
Inherits: | QStringBuilderBase |
Public Functions
QStringBuilder(const A &a, const B &b) |
Detailed Description
\inmodule
QtCore \internal
\reentrant
\since
4.6
\ingroup
tools \ingroup
shared \ingroup
string-processing
To build a QString by multiple concatenations, QString::operator+() is typically used. This causes n - 1 allocations when building a string from n chunks. The same is true for QByteArray.
QStringBuilder uses expression templates to collect the individual chunks, compute the total size, allocate the required amount of memory for the final string object, and copy the chunks into the allocated memory.
The QStringBuilder class is not to be used explicitly in user code. Instances of the class are created as return values of the operator%() function, acting on objects of the following types:
For building QStrings:
- QString, (since 5.10:) QStringView
- QChar, QLatin1Char, (since 5.10:)
char16_t
, - QLatin1StringView,
- (since 5.10:)
const char16_t[]
(u"foo"
), - QByteArray,
char
,const char[]
.
The types in the last list point are only available when QT_NO_CAST_FROM_ASCII
is not defined.
For building QByteArrays:
- QByteArray,
char
,const char[]
.
Concatenating strings with operator%() generally yields better performance than using QString::operator+()
on the same chunks if there are three or more of them, and performs equally well in other cases.
Note: Defining QT_USE_QSTRINGBUILDER
at build time (this is the default when building Qt libraries and tools), will make using '+'
when concatenating strings work the same way as operator%()
.
See also QLatin1StringView and QString.
Member Function Documentation
QStringBuilder::QStringBuilder(const A &a, const B &b)
\internal
Constructs a QStringBuilder from a and b.