summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2010-03-05 11:55:14 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2010-03-05 15:57:23 (GMT)
commitca33c72439ba92ca8bdeca4d172550602f01f0cc (patch)
tree97b3ccacd045ec3909cee3253a1d63a8c64902c8 /src
parent2101a184311d12e1e52a0d421f7a81a28ca333d3 (diff)
downloadQt-ca33c72439ba92ca8bdeca4d172550602f01f0cc.zip
Qt-ca33c72439ba92ca8bdeca4d172550602f01f0cc.tar.gz
Qt-ca33c72439ba92ca8bdeca4d172550602f01f0cc.tar.bz2
Make QString::toUtf8() also use QUtf8.
Reviewed-By: Denis Dzyubenko
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qstring.cpp44
1 files changed, 5 insertions, 39 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index 9097570..703ec67 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -563,7 +563,7 @@ const QString::Null QString::null = { };
\list
\o toAscii() returns an 8-bit string encoded using the codec
- specified by QTextCodec::codecForCStrings (by default, that's
+ specified by QTextCodec::codecForCStrings (by default, that is
Latin 1).
\o toLatin1() returns a Latin-1 (ISO 8859-1) encoded 8-bit string.
\o toUtf8() returns a UTF-8 encoded 8-bit string. UTF-8 is a
@@ -3662,44 +3662,10 @@ QByteArray QString::toLocal8Bit() const
*/
QByteArray QString::toUtf8() const
{
- QByteArray ba;
- if (d->size) {
- int l = d->size;
- int rlen = l*3+1;
- ba.resize(rlen);
- uchar *cursor = (uchar*)ba.data();
- const ushort *ch =d->data;
- for (int i=0; i < l; i++) {
- uint u = *ch;
- if (u < 0x80) {
- *cursor++ = (uchar)u;
- } else {
- if (u < 0x0800) {
- *cursor++ = 0xc0 | ((uchar) (u >> 6));
- } else {
- if (QChar(u).isHighSurrogate() && i < l-1) {
- ushort low = ch[1];
- if (QChar(low).isLowSurrogate()) {
- ++ch;
- ++i;
- u = QChar::surrogateToUcs4(u,low);
- }
- }
- if (u > 0xffff) {
- *cursor++ = 0xf0 | ((uchar) (u >> 18));
- *cursor++ = 0x80 | (((uchar) (u >> 12)) & 0x3f);
- } else {
- *cursor++ = 0xe0 | ((uchar) (u >> 12));
- }
- *cursor++ = 0x80 | (((uchar) (u >> 6)) & 0x3f);
- }
- *cursor++ = 0x80 | ((uchar) (u&0x3f));
- }
- ++ch;
- }
- ba.resize(cursor - (uchar*)ba.constData());
- }
- return ba;
+ if (isNull())
+ return QByteArray();
+
+ return QUtf8::convertFromUnicode(constData(), length(), 0);
}
/*!