path: root/src/corelib/tools/qstringbuilder.h
diff options
authorThiago Macieira <>2012-04-25 17:55:36 +0200
committerQt by Nokia <>2012-05-07 05:07:16 +0200
commit8ddd8c8ba956d5cabc23121fbe633e3135b7b5b2 (patch)
tree86b42c84b88079735ec766986f459aba4df61d20 /src/corelib/tools/qstringbuilder.h
parent592fe0a02609503670cc9238d1a4ad29e4e65185 (diff)
Change QStringBuilder to use UTF-8 too
This commit completes the previous commit so that both QString and QStringBuilder now operate on UTF-8 input. A small fix was required in QStringBuilder: an if clause isn't enough to separate the two append versions. Since there are no QString functions that append to char*, if we're converting to a QByteArray, we need to go through a QString first in a separate function. Change-Id: Ic503340c5d0c32d420c90c91cc2e0fc1ae9230f3 Reviewed-by: Lars Knoll <>
Diffstat (limited to 'src/corelib/tools/qstringbuilder.h')
1 files changed, 20 insertions, 7 deletions
diff --git a/src/corelib/tools/qstringbuilder.h b/src/corelib/tools/qstringbuilder.h
index 9b1cd1ee7e..6b258eb09a 100644
--- a/src/corelib/tools/qstringbuilder.h
+++ b/src/corelib/tools/qstringbuilder.h
@@ -381,15 +381,11 @@ operator+(const A &a, const B &b)
+namespace QtStringBuilder {
template <typename A, typename B>
-QByteArray &operator+=(QByteArray &a, const QStringBuilder<A, B> &b)
+QByteArray &appendToByteArray(QByteArray &a, const QStringBuilder<A, B> &b, char)
- if (sizeof(typename QConcatenable< QStringBuilder<A, B> >::ConvertTo::value_type) == sizeof(QChar)) {
- //it is not save to optimize as in utf8 it is not possible to compute the size
- return a += QString(b);
- }
+ // append 8-bit data to a byte array
int len = a.size() + QConcatenable< QStringBuilder<A, B> >::size(b);
char *it = + a.size();
@@ -398,6 +394,23 @@ QByteArray &operator+=(QByteArray &a, const QStringBuilder<A, B> &b)
return a;
+template <typename A, typename B>
+QByteArray &appendToByteArray(QByteArray &a, const QStringBuilder<A, B> &b, QChar)
+ // append UTF-16 data to the byte array
+ return a += QString(b);
+template <typename A, typename B>
+QByteArray &operator+=(QByteArray &a, const QStringBuilder<A, B> &b)
+ return QtStringBuilder::appendToByteArray(a, b,
+ typename QConcatenable< QStringBuilder<A, B> >::ConvertTo::value_type());
template <typename A, typename B>
QString &operator+=(QString &a, const QStringBuilder<A, B> &b)