Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

QByteArray QString::toUtf8 (  )  const

Returns a UTF-8 representation of the string as a QByteArray.

See also:
fromUtf8(), toAscii(), toLatin1(), toLocal8Bit(), QTextCodec

Definition at line 3094 of file qstring.cpp.

References QByteArray::constData(), QByteArray::data(), QByteArray::resize(), QByteArray::size(), and QChar::surrogateToUcs4().

Referenced by QFormBuilder::applyProperties(), QAbstractFormBuilder::applyProperties(), QAbstractFormBuilder::computeProperties(), QDBusConnection::connectToBus(), QDBusUtil::isValidSignature(), QDBusUtil::isValidSingleSignature(), QDBusError::QDBusError(), QDBusServer::QDBusServer(), QAbstractFormBuilder::save(), QWidget::setWindowRole(), QDomDocument::toByteArray(), QUrl::toPercentEncoding(), and Q3UriDrag::unicodeUriToUri().

{
    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;
}


Generated by  Doxygen 1.6.0   Back to index