📄 qxmlstream.g
字号:
-------------------------------------------------------------------------------- Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.---- This file is part of the QtXML module of the Qt Toolkit.---- This file may be used under the terms of the GNU General Public-- License version 2.0 as published by the Free Software Foundation-- and appearing in the file LICENSE.GPL included in the packaging of-- this file. Please review the following information to ensure GNU-- General Public Licensing requirements will be met:-- http://trolltech.com/products/qt/licenses/licensing/opensource/---- If you are unsure which license is appropriate for your use, please-- review the following information:-- http://trolltech.com/products/qt/licenses/licensing/licensingoverview-- or contact the sales department at sales@trolltech.com.---- In addition, as a special exception, Trolltech gives you certain-- additional rights. These rights are described in the Trolltech GPL-- Exception version 1.0, which can be found at-- http://www.trolltech.com/products/qt/gplexception/ and in the file-- GPL_EXCEPTION.txt in this package.---- In addition, as a special exception, Trolltech, as the sole copyright-- holder for Qt Designer, grants users of the Qt/Eclipse Integration-- plug-in the right for the Qt/Eclipse Integration to link to-- functionality provided by Qt Designer and its related libraries.---- Trolltech reserves all rights not expressly granted herein.---- This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE-- WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.------------------------------------------------------------------------------%parser QXmlStreamReader_Table%merged_output qxmlstream_p.h%expect 0%token NOTOKEN%token SPACE " "%token LANGLE "<"%token RANGLE ">"%token AMPERSAND "&"%token HASH "#"%token QUOTE "\'"%token DBLQUOTE "\""%token LBRACK "["%token RBRACK "]"%token LPAREN "("%token RPAREN ")"%token PIPE "|"%token EQ "="%token PERCENT "%"%token SLASH "/"%token COLON ":"%token SEMICOLON ";"%token COMMA ","%token DASH "-"%token PLUS "+"%token STAR "*"%token DOT "."%token QUESTIONMARK "?"%token BANG "!"%token LETTER "[a-zA-Z]"%token DIGIT "[0-9]"-- after langle_bang%token CDATA_START "[CDATA["%token DOCTYPE "DOCTYPE"%token ELEMENT "ELEMENT"%token ATTLIST "ATTLIST"%token ENTITY "ENTITY"%token NOTATION "NOTATION"-- entity decl%token SYSTEM "SYSTEM"%token PUBLIC "PUBLIC"%token NDATA "NDATA"-- default decl%token REQUIRED "REQUIRED"%token IMPLIED "IMPLIED"%token FIXED "FIXED"-- conent spec%token EMPTY "EMPTY"%token ANY "ANY"%token PCDATA "PCDATA"-- error%token ERROR-- entities%token PARSE_ENTITY%token ENTITY_DONE-- att type%token CDATA "CDATA"%token ID "ID"%token IDREF "IDREF"%token IDREFS "IDREFS"%token ENTITY "ENTITY"%token ENTITIES "ENTITIES"%token NMTOKEN "NMTOKEN"%token NMTOKENS "NMTOKENS"-- xml declaration%token XML "<?xml"%token VERSION "version"%start document/.#include <QCoreApplication>template <typename T> class QXmlStreamSimpleStack { T *data; int tos, cap;public: inline QXmlStreamSimpleStack():data(0), tos(-1), cap(0){} inline ~QXmlStreamSimpleStack(){ if (data) qFree(data); } inline void reserve(int extraCapacity) { if (tos + extraCapacity + 1 > cap) { cap = qMax(tos + extraCapacity + 1, cap << 1 ); data = reinterpret_cast<T *>(qRealloc(data, cap * sizeof(T))); } } inline T &push() { reserve(1); return data[++tos]; } inline T &rawPush() { return data[++tos]; } inline const T &top() const { return data[tos]; } inline T &top() { return data[tos]; } inline T &pop() { return data[tos--]; } inline T &operator[](int index) { return data[index]; } inline const T &at(int index) const { return data[index]; } inline int size() const { return tos + 1; } inline void resize(int s) { tos = s - 1; } inline bool isEmpty() const { return tos < 0; } inline void clear() { tos = -1; }};class QXmlStream{ Q_DECLARE_TR_FUNCTIONS(QXmlStream)};class QXmlStreamPrivateTagStack {public: struct NamespaceDeclaration { QStringRef prefix; QStringRef namespaceUri; }; struct Tag { QStringRef name; QStringRef qualifiedName; NamespaceDeclaration namespaceDeclaration; int tagStackStringStorageSize; int namespaceDeclarationsSize; }; QXmlStreamPrivateTagStack(); QXmlStreamSimpleStack<NamespaceDeclaration> namespaceDeclarations; QString tagStackStringStorage; int tagStackStringStorageSize; int tagStackDefaultStringStorageSize; bool tagsDone; inline QStringRef addToStringStorage(const QStringRef &s) { int pos = tagStackStringStorageSize; int sz = s.size(); if (pos != tagStackStringStorage.size()) tagStackStringStorage.resize(pos); tagStackStringStorage.insert(pos, s.unicode(), sz); tagStackStringStorageSize += sz; return QStringRef(&tagStackStringStorage, pos, sz); } inline QStringRef addToStringStorage(const QString &s) { int pos = tagStackStringStorageSize; int sz = s.size(); if (pos != tagStackStringStorage.size()) tagStackStringStorage.resize(pos); tagStackStringStorage.insert(pos, s.unicode(), sz); tagStackStringStorageSize += sz; return QStringRef(&tagStackStringStorage, pos, sz); } QXmlStreamSimpleStack<Tag> tagStack; inline void initTagStack() { tagStackStringStorageSize = tagStackDefaultStringStorageSize; namespaceDeclarations.resize(1); } inline Tag &tagStack_pop() { Tag& tag = tagStack.pop(); tagStackStringStorageSize = tag.tagStackStringStorageSize; namespaceDeclarations.resize(tag.namespaceDeclarationsSize); tagsDone = tagStack.isEmpty(); return tag; } inline Tag &tagStack_push() { Tag &tag = tagStack.push(); tag.tagStackStringStorageSize = tagStackStringStorageSize; tag.namespaceDeclarationsSize = namespaceDeclarations.size(); return tag; }};class QXmlStreamReaderPrivate : public QXmlStreamReader_Table, public QXmlStreamPrivateTagStack{ QXmlStreamReader *q_ptr; Q_DECLARE_PUBLIC(QXmlStreamReader)public: QXmlStreamReaderPrivate(QXmlStreamReader *q); ~QXmlStreamReaderPrivate(); void init(); QByteArray rawReadBuffer; QByteArray dataBuffer; uchar firstByte; qint64 nbytesread; QString readBuffer; int readBufferPos; QXmlStreamSimpleStack<uint> putStack; struct Entity { Entity(const QString& str = QString()) :value(str), external(false), unparsed(false), literal(false), hasBeenParsed(false), isCurrentlyReferenced(false){} static inline Entity createLiteral(const QString &entity) { Entity result(entity); result.literal = result.hasBeenParsed = true; return result; } QString value; uint external : 1; uint unparsed : 1; uint literal : 1; uint hasBeenParsed : 1; uint isCurrentlyReferenced : 1; }; QHash<QString, Entity> entityHash; QHash<QString, Entity> parameterEntityHash; QXmlStreamSimpleStack<Entity *>entityReferenceStack; inline bool referenceEntity(Entity &entity) { if (entity.isCurrentlyReferenced) { raiseWellFormedError(QXmlStream::tr("Recursive entity detected.")); return false; } entity.isCurrentlyReferenced = true; entityReferenceStack.push() = &entity; injectToken(ENTITY_DONE); return true; } QIODevice *device; bool deleteDevice;#ifndef QT_NO_TEXTCODEC QTextCodec *codec; QTextDecoder *decoder;#endif bool atEnd; /*! \sa setType() */ QXmlStreamReader::TokenType type; QXmlStreamReader::Error error; QString errorString; qint64 lineNumber, lastLineStart, characterOffset; void write(const QString &); void write(const char *); QXmlStreamAttributes attributes; QStringRef namespaceForPrefix(const QStringRef &prefix); void resolveTag(); void resolvePublicNamespaces(); void resolveDtd(); uint resolveCharRef(int symbolIndex); bool checkStartDocument(); void startDocument(const QStringRef &version); void parseError(); void checkPublicLiteral(const QStringRef &publicId); bool scanDtd; QStringRef lastAttributeValue; bool lastAttributeIsCData; struct DtdAttribute { QStringRef tagName; QStringRef attributeQualifiedName; QStringRef attributePrefix; QStringRef attributeName; QStringRef defaultValue; bool isCDATA; }; QXmlStreamSimpleStack<DtdAttribute> dtdAttributes; struct NotationDeclaration { QStringRef name; QStringRef publicId; QStringRef systemId; }; QXmlStreamSimpleStack<NotationDeclaration> notationDeclarations; QXmlStreamNotationDeclarations publicNotationDeclarations; QXmlStreamNamespaceDeclarations publicNamespaceDeclarations; struct EntityDeclaration { QStringRef name; QStringRef notationName; QStringRef publicId; QStringRef systemId; QStringRef value; bool parameter; bool external; inline void clear() { name.clear(); notationName.clear(); publicId.clear(); systemId.clear(); value.clear(); parameter = external = false; } }; QXmlStreamSimpleStack<EntityDeclaration> entityDeclarations; QXmlStreamEntityDeclarations publicEntityDeclarations; QStringRef text; QStringRef prefix, namespaceUri, qualifiedName, name; QStringRef processingInstructionTarget, processingInstructionData; uint isEmptyElement : 1; uint isWhitespace : 1; uint isCDATA : 1; uint standalone : 1; uint hasCheckedStartDocument : 1; uint normalizeLiterals : 1; uint hasSeenTag : 1; uint inParseEntity : 1; uint referenceToUnparsedEntityDetected : 1; uint referenceToParameterEntityDetected : 1; uint hasExternalDtdSubset : 1; uint lockEncoding : 1; uint namespaceProcessing : 1; int resumeReduction; void resume(int rule); inline bool entitiesMustBeDeclared() const { return (!inParseEntity && (standalone || (!referenceToUnparsedEntityDetected && !referenceToParameterEntityDetected // Errata 13 as of 2006-04-25 && !hasExternalDtdSubset))); } // qlalr parser int tos; int stack_size; struct Value { int pos; int len; int prefix; ushort c; }; Value *sym_stack; int *state_stack; inline void reallocateStack(); inline Value &sym(int index) const { return sym_stack[tos + index - 1]; } QString textBuffer; inline void clearTextBuffer() { if (!scanDtd) { textBuffer.resize(0); textBuffer.reserve(256); } } struct Attribute { Value key; Value value; }; QXmlStreamSimpleStack<Attribute> attributeStack; inline QStringRef symString(int index) { const Value &symbol = sym(index); return QStringRef(&textBuffer, symbol.pos + symbol.prefix, symbol.len - symbol.prefix); } inline QStringRef symName(int index) { const Value &symbol = sym(index); return QStringRef(&textBuffer, symbol.pos, symbol.len); } inline QStringRef symString(int index, int offset) { const Value &symbol = sym(index); return QStringRef(&textBuffer, symbol.pos + symbol.prefix + offset, symbol.len - symbol.prefix - offset); } inline QStringRef symPrefix(int index) { const Value &symbol = sym(index); if (symbol.prefix) return QStringRef(&textBuffer, symbol.pos, symbol.prefix - 1); return QStringRef(); } inline QStringRef symString(const Value &symbol) { return QStringRef(&textBuffer, symbol.pos + symbol.prefix, symbol.len - symbol.prefix); } inline QStringRef symName(const Value &symbol) { return QStringRef(&textBuffer, symbol.pos, symbol.len); } inline QStringRef symPrefix(const Value &symbol) { if (symbol.prefix) return QStringRef(&textBuffer, symbol.pos, symbol.prefix - 1); return QStringRef(); } inline void clearSym() { Value &val = sym(1); val.pos = textBuffer.size(); val.len = 0; } short token; ushort token_char; uint filterCarriageReturn(); inline uint getChar(); inline uint peekChar(); inline void putChar(uint c) { putStack.push() = c; } inline void putChar(QChar c) { putStack.push() = c.unicode(); } void putString(const QString &s, int from = 0); void putStringLiteral(const QString &s); void putReplacement(const QString &s); void putReplacementInAttributeValue(const QString &s); ushort getChar_helper();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -