diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2012-04-25 17:55:36 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-07 05:07:16 +0200 |
commit | 8ddd8c8ba956d5cabc23121fbe633e3135b7b5b2 (patch) | |
tree | 86b42c84b88079735ec766986f459aba4df61d20 /src/corelib/tools/qstringbuilder.cpp | |
parent | 592fe0a02609503670cc9238d1a4ad29e4e65185 (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 <lars.knoll@nokia.com>
Diffstat (limited to 'src/corelib/tools/qstringbuilder.cpp')
-rw-r--r-- | src/corelib/tools/qstringbuilder.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/corelib/tools/qstringbuilder.cpp b/src/corelib/tools/qstringbuilder.cpp index a044cca3c9..2fe556096b 100644 --- a/src/corelib/tools/qstringbuilder.cpp +++ b/src/corelib/tools/qstringbuilder.cpp @@ -108,12 +108,24 @@ void QAbstractConcatenable::convertFromAscii(const char *a, int len, QChar *&out if (len == -1) { if (!a) return; - while (*a) + while (*a && uchar(*a) < 0x80U) *out++ = QLatin1Char(*a++); + if (!*a) + return; } else { - for (int i = 0; i < len; ++i) + int i; + for (i = 0; i < len && uchar(a[i]) < 0x80U; ++i) *out++ = QLatin1Char(a[i]); + if (i == len) + return; + a += i; + len -= i; } + + // we need to complement with UTF-8 appending + QString tmp = QString::fromUtf8(a, len); + memcpy(out, reinterpret_cast<const char *>(tmp.constData()), sizeof(QChar) * tmp.size()); + out += tmp.size(); } QT_END_NAMESPACE |