diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qstring.h | 3 | ||||
-rw-r--r-- | src/corelib/tools/qstringbuilder.h | 29 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index b54258f..002e516 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -485,6 +485,9 @@ public: const_iterator constEnd() const; // STL compatibility + typedef const QChar & const_reference; + typedef QChar & reference; + typedef QChar value_type; inline void push_back(QChar c) { append(c); } inline void push_back(const QString &s) { append(s); } inline void push_front(QChar c) { prepend(c); } diff --git a/src/corelib/tools/qstringbuilder.h b/src/corelib/tools/qstringbuilder.h index 260b574..2d3475f 100644 --- a/src/corelib/tools/qstringbuilder.h +++ b/src/corelib/tools/qstringbuilder.h @@ -419,6 +419,35 @@ operator+(const A &a, const B &b) } #endif +template <typename A, typename B> +QByteArray &operator+=(QByteArray &a, const QStringBuilder<A, B> &b) +{ +#ifndef QT_NO_CAST_TO_ASCII + 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); + } +#endif + int len = a.size() + QConcatenable< QStringBuilder<A, B> >::size(b); + a.reserve(len); + char *it = a.data() + a.size(); + QConcatenable< QStringBuilder<A, B> >::appendTo(b, it); + a.resize(len); //we need to resize after the appendTo for the case str+=foo+str + return a; +} + +template <typename A, typename B> +QString &operator+=(QString &a, const QStringBuilder<A, B> &b) +{ + int len = a.size() + QConcatenable< QStringBuilder<A, B> >::size(b); + a.reserve(len); + QChar *it = a.data() + a.size(); + QConcatenable< QStringBuilder<A, B> >::appendTo(b, it); + a.resize(it - a.constData()); //may be smaller than len if there was conversion from utf8 + return a; +} + + QT_END_NAMESPACE QT_END_HEADER |