⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qsettings.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            if (result.startsWith(QLatin1Char('@')))                result.prepend(QLatin1Char('@'));            break;        }#ifndef QT_NO_GEOM_VARIANT        case QVariant::Rect: {            QRect r = qvariant_cast<QRect>(v);            result += QLatin1String("@Rect(");            result += QString::number(r.x());            result += QLatin1Char(' ');            result += QString::number(r.y());            result += QLatin1Char(' ');            result += QString::number(r.width());            result += QLatin1Char(' ');            result += QString::number(r.height());            result += QLatin1Char(')');            break;        }        case QVariant::Size: {            QSize s = qvariant_cast<QSize>(v);            result += QLatin1String("@Size(");            result += QString::number(s.width());            result += QLatin1Char(' ');            result += QString::number(s.height());            result += QLatin1Char(')');            break;        }        case QVariant::Point: {            QPoint p = qvariant_cast<QPoint>(v);            result += QLatin1String("@Point(");            result += QString::number(p.x());            result += QLatin1Char(' ');            result += QString::number(p.y());            result += QLatin1Char(')');            break;        }#endif // !QT_NO_GEOM_VARIANT        default: {#ifndef QT_NO_DATASTREAM            QByteArray a;            {                QDataStream s(&a, QIODevice::WriteOnly);                s.setVersion(QDataStream::Qt_4_0);                s << v;            }            result = QLatin1String("@Variant(");            result += QString::fromLatin1(a.constData(), a.size());            result += QLatin1Char(')');#else            Q_ASSERT("QSettings: Cannot save custom types without QDataStream support");#endif            break;        }    }    return result;}QVariant QSettingsPrivate::stringToVariant(const QString &s){    if (s.startsWith(QLatin1Char('@'))) {        if (s.endsWith(QLatin1Char(')'))) {            if (s.startsWith(QLatin1String("@ByteArray("))) {                return QVariant(s.toLatin1().mid(11, s.size() - 12));            } else if (s.startsWith(QLatin1String("@Variant("))) {#ifndef QT_NO_DATASTREAM                QByteArray a(s.toLatin1().mid(9));                QDataStream stream(&a, QIODevice::ReadOnly);                stream.setVersion(QDataStream::Qt_4_0);                QVariant result;                stream >> result;                return result;#else                Q_ASSERT("QSettings: Cannot load custom types without QDataStream support");#endif#ifndef QT_NO_GEOM_VARIANT            } else if (s.startsWith(QLatin1String("@Rect("))) {                QStringList args = QSettingsPrivate::splitArgs(s, 5);                if (args.size() == 4)                    return QVariant(QRect(args[0].toInt(), args[1].toInt(), args[2].toInt(), args[3].toInt()));            } else if (s.startsWith(QLatin1String("@Size("))) {                QStringList args = QSettingsPrivate::splitArgs(s, 5);                if (args.size() == 2)                    return QVariant(QSize(args[0].toInt(), args[1].toInt()));            } else if (s.startsWith(QLatin1String("@Point("))) {                QStringList args = QSettingsPrivate::splitArgs(s, 6);                if (args.size() == 2)                    return QVariant(QPoint(args[0].toInt(), args[1].toInt()));#endif            } else if (s == QLatin1String("@Invalid()")) {                return QVariant();            }        }        if (s.startsWith(QLatin1String("@@")))            return QVariant(s.mid(1));    }    return QVariant(s);}static const char hexDigits[] = "0123456789ABCDEF";void QSettingsPrivate::iniEscapedKey(const QString &key, QByteArray &result){    result.reserve(result.length() + key.length() * 3 / 2);    for (int i = 0; i < key.size(); ++i) {        uint ch = key.at(i).unicode();        if (ch == '/') {            result += '\\';        } else if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9'                || ch == '_' || ch == '-' || ch == '.') {            result += (char)ch;        } else if (ch <= 0xFF) {            result += '%';            result += hexDigits[ch / 16];            result += hexDigits[ch % 16];        } else {            result += "%U";            QByteArray hexCode;            for (int i = 0; i < 4; ++i) {                hexCode.prepend(hexDigits[ch % 16]);                ch >>= 4;            }            result += hexCode;        }    }}bool QSettingsPrivate::iniUnescapedKey(const QByteArray &key, int from, int to, QString &result){    bool lowercaseOnly = true;    int i = from;    result.reserve(result.length() + (to - from));    while (i < to) {        int ch = (uchar)key.at(i);        if (ch == '\\') {            result += QLatin1Char('/');            ++i;            continue;        }        if (ch != '%' || i == to - 1) {            if (uint(ch - 'A') <= 'Z' - 'A') // only for ASCII                lowercaseOnly = false;            result += QLatin1Char(ch);            ++i;            continue;        }        int numDigits = 2;        int firstDigitPos = i + 1;        ch = key.at(i + 1);        if (ch == 'U') {            ++firstDigitPos;            numDigits = 4;        }        if (firstDigitPos + numDigits > to) {            result += QLatin1Char('%');            // ### missing U            ++i;            continue;        }        bool ok;        ch = key.mid(firstDigitPos, numDigits).toInt(&ok, 16);        if (!ok) {            result += QLatin1Char('%');            // ### missing U            ++i;            continue;        }        QChar qch(ch);        if (qch.isUpper())            lowercaseOnly = false;        result += qch;        i = firstDigitPos + numDigits;    }    return lowercaseOnly;}void QSettingsPrivate::iniEscapedString(const QString &str, QByteArray &result){    bool needsQuotes = false;    bool escapeNextIfDigit = false;    int i;    int startPos = result.size();    result.reserve(startPos + str.size() * 3 / 2);    for (i = 0; i < str.size(); ++i) {        uint ch = str.at(i).unicode();        if (ch == ';' || ch == ',' || ch == '=')            needsQuotes = true;        if (escapeNextIfDigit                && ((ch >= '0' && ch <= '9')                    || (ch >= 'a' && ch <= 'f')                    || (ch >= 'A' && ch <= 'F'))) {            result += "\\x";            result += QByteArray::number(ch, 16);            continue;        }        escapeNextIfDigit = false;        switch (ch) {        case '\0':            result += "\\0";            escapeNextIfDigit = true;            break;        case '\a':            result += "\\a";            break;        case '\b':            result += "\\b";            break;        case '\f':            result += "\\f";            break;        case '\n':            result += "\\n";            break;        case '\r':            result += "\\r";            break;        case '\t':            result += "\\t";            break;        case '\v':            result += "\\v";            break;        case '"':        case '\\':            result += '\\';            result += (char)ch;            break;        default:            if (ch <= 0x1F || ch >= 0x7F) {                result += "\\x";                result += QByteArray::number(ch, 16);                escapeNextIfDigit = true;            } else {                result += (char)ch;            }        }    }    if (needsQuotes            || (startPos < result.size() && (result.at(startPos) == ' '                                                || result.at(result.size() - 1) == ' '))) {        result.insert(startPos, '"');        result += '"';    }}inline static void iniChopTrailingSpaces(QString &str){    int n = str.size() - 1;    QChar ch;    while (n >= 0 && ((ch = str.at(n)) == QLatin1Char(' ') || ch == QLatin1Char('\t')))        str.truncate(n--);}void QSettingsPrivate::iniEscapedStringList(const QStringList &strs, QByteArray &result){    if (strs.isEmpty()) {        /*            We need to distinguish between empty lists and one-item            lists that contain an empty string. Ideally, we'd have a            @EmptyList() symbol but that would break compatibility            with Qt 4.0. @Invalid() stands for QVariant(), and            QVariant().toStringList() returns an empty QStringList,            so we're in good shape.            ### Qt 5: Use a nicer syntax, e.g. @List, for variant lists        */        result += "@Invalid()";    } else {        for (int i = 0; i < strs.size(); ++i) {            if (i != 0)                result += ", ";            iniEscapedString(strs.at(i), result);        }    }}bool QSettingsPrivate::iniUnescapedStringList(const QByteArray &str, int from, int to,                                              QString &stringResult, QStringList &stringListResult){    static const char escapeCodes[][2] =    {        { 'a', '\a' },        { 'b', '\b' },        { 'f', '\f' },        { 'n', '\n' },        { 'r', '\r' },        { 't', '\t' },        { 'v', '\v' },        { '"', '"' },        { '?', '?' },        { '\'', '\'' },        { '\\', '\\' }    };    static const int numEscapeCodes = sizeof(escapeCodes) / sizeof(escapeCodes[0]);    bool isStringList = false;    bool inQuotedString = false;    bool currentValueIsQuoted = false;    int escapeVal = 0;    int i = from;    char ch;StSkipSpaces:    while (i < to && ((ch = str.at(i)) == ' ' || ch == '\t'))        ++i;    // fallthroughStNormal:    while (i < to) {        switch (str.at(i)) {        case '\\':            ++i;            if (i >= to)                goto end;            ch = str.at(i++);            for (int j = 0; j < numEscapeCodes; ++j) {                if (ch == escapeCodes[j][0]) {                    stringResult += QLatin1Char(escapeCodes[j][1]);                    goto StNormal;                }            }            if (ch == 'x') {                escapeVal = 0;                if (i >= to)                    goto end;                ch = str.at(i);                if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f'))                    goto StHexEscape;            } else if (ch >= '0' && ch <= '7') {                escapeVal = ch - '0';                goto StOctEscape;            } else if (ch == '\n' || ch == '\r') {                if (i < to) {                    char ch2 = str.at(i);                    // \n, \r, \r\n, and \n\r are legitimate line terminators in INI files                    if ((ch2 == '\n' || ch2 == '\r') && ch2 != ch)                        ++i;                }            } else {                // the character is skipped            }            break;        case '"':            ++i;            currentValueIsQuoted = true;            inQuotedString = !inQuotedString;            if (!inQuotedString)                goto StSkipSpaces;            break;        case ',':            if (!inQuotedString) {                if (!currentValueIsQuoted)                    iniChopTrailingSpaces(stringResult);                if (!isStringList) {                    isStringList = true;                    stringListResult.clear();                    stringResult.squeeze();                }                stringListResult.append(stringResult);                stringResult.clear();                currentValueIsQuoted = false;                ++i;                goto StSkipSpaces;            }            // fallthrough        default: {            int j = i + 1;            while (j < to) {                ch = str.at(j);                if (ch == '\\' || ch == '"' || ch == ',')                    break;                ++j;            }            int n = stringResult.size();            stringResult.resize(n + (j - i));            QChar *resultData = stringResult.data() + n;            for (int k = i; k < j; ++k)                *resultData++ = QLatin1Char(str.at(k));            i = j;        }        }    }    goto end;StHexEscape:    if (i >= to) {        stringResult += QChar(escapeVal);        goto end;    }    ch = str.at(i);    if (ch >= 'a')

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -