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

📄 qxmlstream.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            return true;        if (scanString(spell[NMTOKEN], NMTOKEN))            return true;        return scanString(spell[NMTOKENS], NMTOKENS);    default:        ;    }    return false;}/*! \internal Scan strings with quotes or apostrophes surround them. For instance, attributes, the version and encoding field in the XML prolog and entity declarations. If normalizeLiterals is set to true, the function also normalizes whitespace. It is set to true when the first start tag is encountered. */inline int QXmlStreamReaderPrivate::fastScanLiteralContent(){    int n = 0;    uint c;    while ((c = getChar())) {        switch (ushort(c)) {        case 0xfffe:        case 0xffff:        case 0:            /* The putChar() call is necessary so the parser re-gets             * the character from the input source, when raising an error. */            putChar(c);            return n;        case '\r':            if (filterCarriageReturn() == 0)                return n;            // fall through        case '\n':            ++lineNumber;            lastLineStart = characterOffset + readBufferPos;            // fall through        case ' ':        case '\t':            if (normalizeLiterals)                textBuffer.inline_append(QLatin1Char(' '));            else                textBuffer.inline_append(c);            ++n;            break;        case '&':        case '<':        case '\"':        case '\'':            if (!(c & 0xff0000)) {                putChar(c);                return n;            }            // fall through        default:            textBuffer.inline_append(c);            ++n;        }    }    return n;}inline int QXmlStreamReaderPrivate::fastScanSpace(){    int n = 0;    ushort c;    while ((c = getChar())) {        switch (c) {        case '\r':            if ((c = filterCarriageReturn()) == 0)                return n;            // fall through        case '\n':            ++lineNumber;            lastLineStart = characterOffset + readBufferPos;            // fall through        case ' ':        case '\t':            textBuffer.inline_append(c);            ++n;            break;        default:            putChar(c);            return n;        }    }    return n;}/*!  \internal  Used for text nodes essentially. That is, characters appearing  inside elements. */inline int QXmlStreamReaderPrivate::fastScanContentCharList(){    int n = 0;    uint c;    while ((c = getChar())) {        switch (ushort(c)) {        case 0xfffe:        case 0xffff:        case 0:            putChar(c);            return n;        case ']': {            int pos = textBuffer.size();            textBuffer.inline_append(ushort(c));            ++n;            while ((c = getChar()) == ']') {                textBuffer.inline_append(ushort(c));                ++n;            }            if (c == 0) {                putString(textBuffer, pos);                textBuffer.resize(pos);            } else if (c == '>') {                raiseWellFormedError(QXmlStream::tr("Sequence ']]>' not allowed in content."));            } else {                putChar(c);                break;            }            return n;        } break;        case '\r':            if ((c = filterCarriageReturn()) == 0)                return n;            // fall through        case '\n':            ++lineNumber;            lastLineStart = characterOffset + readBufferPos;            // fall through        case ' ':        case '\t':            textBuffer.inline_append(ushort(c));            ++n;            break;        case '&':        case '<':            if (!(c & 0xff0000)) {                putChar(c);                return n;            }            // fall through        default:            if (c < 0x20) {                putChar(c);                return n;            }            isWhitespace = false;            textBuffer.inline_append(ushort(c));            ++n;        }    }    return n;}inline int QXmlStreamReaderPrivate::fastScanName(int *prefix){    int n = 0;    ushort c;    while ((c = getChar())) {        switch (c) {        case '\n':        case ' ':        case '\t':        case '\r':        case '&':        case '#':        case '\'':        case '\"':        case '<':        case '>':        case '[':        case ']':        case '=':        case '%':        case '/':        case ';':        case '?':        case '!':        case '^':        case '|':        case ',':        case '(':        case ')':        case '+':        case '*':            putChar(c);            if (prefix && *prefix == n+1) {                *prefix = 0;                putChar(':');                --n;            }            return n;        case ':':            if (prefix) {                if (*prefix == 0) {                    *prefix = n+2;                } else { // only one colon allowed according to the namespace spec.                    putChar(c);                    return n;                }            } else {                putChar(c);                return n;            }            // fall through        default:            textBuffer.inline_append(c);            ++n;        }    }    if (prefix)        *prefix = 0;    int pos = textBuffer.size() - n;    putString(textBuffer, pos);    textBuffer.resize(pos);    return 0;}enum NameChar { NameBeginning, NameNotBeginning, NotName };static const char Begi = (char)NameBeginning;static const char NtBg = (char)NameNotBeginning;static const char NotN = (char)NotName;static const char nameCharTable[128] ={// 0x00    NotN, NotN, NotN, NotN, NotN, NotN, NotN, NotN,    NotN, NotN, NotN, NotN, NotN, NotN, NotN, NotN,// 0x10    NotN, NotN, NotN, NotN, NotN, NotN, NotN, NotN,    NotN, NotN, NotN, NotN, NotN, NotN, NotN, NotN,// 0x20 (0x2D is '-', 0x2E is '.')    NotN, NotN, NotN, NotN, NotN, NotN, NotN, NotN,    NotN, NotN, NotN, NotN, NotN, NtBg, NtBg, NotN,// 0x30 (0x30..0x39 are '0'..'9', 0x3A is ':')    NtBg, NtBg, NtBg, NtBg, NtBg, NtBg, NtBg, NtBg,    NtBg, NtBg, Begi, NotN, NotN, NotN, NotN, NotN,// 0x40 (0x41..0x5A are 'A'..'Z')    NotN, Begi, Begi, Begi, Begi, Begi, Begi, Begi,    Begi, Begi, Begi, Begi, Begi, Begi, Begi, Begi,// 0x50 (0x5F is '_')    Begi, Begi, Begi, Begi, Begi, Begi, Begi, Begi,    Begi, Begi, Begi, NotN, NotN, NotN, NotN, Begi,// 0x60 (0x61..0x7A are 'a'..'z')    NotN, Begi, Begi, Begi, Begi, Begi, Begi, Begi,    Begi, Begi, Begi, Begi, Begi, Begi, Begi, Begi,// 0x70    Begi, Begi, Begi, Begi, Begi, Begi, Begi, Begi,    Begi, Begi, Begi, NotN, NotN, NotN, NotN, NotN};static inline NameChar fastDetermineNameChar(QChar ch){    ushort uc = ch.unicode();    if (!(uc & ~0x7f)) // uc < 128        return (NameChar)nameCharTable[uc];    QChar::Category cat = ch.category();    // ### some these categories might be slightly wrong    if ((cat >= QChar::Letter_Uppercase && cat <= QChar::Letter_Other)        || cat == QChar::Number_Letter)        return NameBeginning;    if ((cat >= QChar::Number_DecimalDigit && cat <= QChar::Number_Other)                || (cat >= QChar::Mark_NonSpacing && cat <= QChar::Mark_Enclosing))        return NameNotBeginning;    return NotName;}inline int QXmlStreamReaderPrivate::fastScanNMTOKEN(){    int n = 0;    uint c;    while ((c = getChar())) {        if (fastDetermineNameChar(c) == NotName) {            putChar(c);            return n;        } else {            ++n;            textBuffer.inline_append(c);        }    }    int pos = textBuffer.size() - n;    putString(textBuffer, pos);    textBuffer.resize(pos);    return n;}bool QXmlStreamReaderPrivate::validateName(const QStringRef &name){    if (fastDetermineNameChar(name.at(0)) != NameBeginning)        return false;    for (int i = 1; i < name.size(); ++i)        if (fastDetermineNameChar(name.at(i)) == NotName)            return false;    return true;}void QXmlStreamReaderPrivate::putString(const QString &s, int from){    putStack.reserve(s.size());    for (int i = s.size()-1; i >= from; --i)        putStack.rawPush() = s.at(i).unicode();}void QXmlStreamReaderPrivate::putStringLiteral(const QString &s){    putStack.reserve(s.size());    for (int i = s.size()-1; i >= 0; --i)        putStack.rawPush() = ((LETTER << 16) | s.at(i).unicode());}void QXmlStreamReaderPrivate::putReplacement(const QString &s){    putStack.reserve(s.size());    for (int i = s.size()-1; i >= 0; --i) {        ushort c = s.at(i).unicode();        if (c == '\n' || c == '\r')            putStack.rawPush() = ((LETTER << 16) | c);        else            putStack.rawPush() = c;    }}void QXmlStreamReaderPrivate::putReplacementInAttributeValue(const QString &s){    putStack.reserve(s.size());    for (int i = s.size()-1; i >= 0; --i) {        ushort c = s.at(i).unicode();        if (c == '&' || c == ';')            putStack.rawPush() = c;        else if (c == '\n' || c == '\r')            putStack.rawPush() = ' ';        else            putStack.rawPush() = ((LETTER << 16) | c);    }}ushort QXmlStreamReaderPrivate::getChar_helper(){    const int BUFFER_SIZE = 8192;    characterOffset += readBufferPos;    readBufferPos = 0;    readBuffer.resize(0);#ifndef QT_NO_TEXTCODEC    if (decoder)        nbytesread = 0;#endif    if (device) {        rawReadBuffer.resize(BUFFER_SIZE);        nbytesread += device->read(rawReadBuffer.data() + nbytesread, BUFFER_SIZE - nbytesread);    } else {        if (nbytesread)            rawReadBuffer += dataBuffer;        else            rawReadBuffer = dataBuffer;        nbytesread = rawReadBuffer.size();        dataBuffer.clear();    }    if (!nbytesread) {        atEnd = true;        return 0;    }#ifndef QT_NO_TEXTCODEC    if (!decoder) {        if (nbytesread < 4) { // the 4 is to cover 0xef 0xbb 0xbf plus                              // one extra for the utf8 codec            atEnd = true;            return 0;        }        int mib = 106; // UTF-8        // look for byte order mark        uchar ch1 = rawReadBuffer.at(0);        uchar ch2 = rawReadBuffer.at(1);        if (ch1 == 0xfe && ch2 == 0xff || ch1 == 0xff && ch2 == 0xfe)            mib = 1015; // UTF-16 with byte order mark        else if (ch1 == 0x3c && ch2 == 0x00)            mib = 1014; // UTF-16LE        else if (ch1 == 0x00 && ch2 == 0x3c)            mib = 1013; // UTF-16BE        codec = QTextCodec::codecForMib(mib);        Q_ASSERT(codec);        decoder = codec->makeDecoder();    }    decoder->toUnicode(&readBuffer, rawReadBuffer.data(), nbytesread);    if(lockEncoding && decoder->hasFailure()) {        raiseWellFormedError(QXmlStream::tr("Encountered incorrectly encoded content."));        readBuffer.clear();        return 0;    }#else    readBuffer = QString::fromLatin1(rawReadBuffer.data(), nbytesread);#endif // QT_NO_TEXTCODEC    readBuffer.reserve(1); // keep capacity when calling resize() next time    if (readBufferPos < readBuffer.size()) {        ushort c = readBuffer.at(readBufferPos++).unicode();        return c;    }    atEnd = true;    return 0;}QStringRef QXmlStreamReaderPrivate::namespaceForPrefix(const QStringRef &prefix){     for (int j = namespaceDeclarations.size() - 1; j >= 0; --j) {         const NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.at(j);         if (namespaceDeclaration.prefix == prefix) {             return namespaceDeclaration.namespaceUri;         }     }#if 1     if (namespaceProcessing && !prefix.isEmpty())         raiseWellFormedError(QXmlStream::tr("Namespace prefix '%1' not declared").arg(prefix.toString()));#endif     return QStringRef();}

⌨️ 快捷键说明

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