From 6d4e9aa86df5e0670914ca1f36b46370f85e171b Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Wed, 7 Jul 2021 18:18:01 +0300 Subject: [PATCH] indent and format QXmlStreamReaderPrivate::parse() Signed-off-by: Ivailo Monev --- src/xml/kernel/qxmlstream_p.h | 1170 ++++++++++++++++++++++------------------- 1 file changed, 617 insertions(+), 553 deletions(-) diff --git a/src/xml/kernel/qxmlstream_p.h b/src/xml/kernel/qxmlstream_p.h index 7642ecb16..648152040 100644 --- a/src/xml/kernel/qxmlstream_p.h +++ b/src/xml/kernel/qxmlstream_p.h @@ -1240,113 +1240,129 @@ bool QXmlStreamReaderPrivate::parse() tos -= QXmlStreamReader_rhs[r]; act = state_stack[tos++]; - ResumeReduction: + ResumeReduction: switch (r) { - case 0: - setType(QXmlStreamReader::EndDocument); - break; + case 0: { + setType(QXmlStreamReader::EndDocument); + break; + } - case 1: - if (type != QXmlStreamReader::Invalid) { - if (hasSeenTag || inParseEntity) { - setType(QXmlStreamReader::EndDocument); - } else { - raiseError(QXmlStreamReader::NotWellFormedError, QXmlStream::tr("Start tag expected.")); - // reset the parser - tos = 0; - state_stack[tos++] = 0; - state_stack[tos] = 0; - return false; + case 1: { + if (type != QXmlStreamReader::Invalid) { + if (hasSeenTag || inParseEntity) { + setType(QXmlStreamReader::EndDocument); + } else { + raiseError(QXmlStreamReader::NotWellFormedError, QXmlStream::tr("Start tag expected.")); + // reset the parser + tos = 0; + state_stack[tos++] = 0; + state_stack[tos] = 0; + return false; + } } + break; } - break; - case 10: - entityReferenceStack.pop()->isCurrentlyReferenced = false; - clearSym(); - break; + case 10: { + entityReferenceStack.pop()->isCurrentlyReferenced = false; + clearSym(); + break; + } - case 11: - if (!scanString(QXmlStreamReader_spell[VERSION], VERSION, false) && atEnd) { - resume(11); - return false; + case 11: { + if (!scanString(QXmlStreamReader_spell[VERSION], VERSION, false) && atEnd) { + resume(11); + return false; + } + break; } - break; - case 12: - setType(QXmlStreamReader::StartDocument); - documentVersion = symString(6); - startDocument(); - break; + case 12: { + setType(QXmlStreamReader::StartDocument); + documentVersion = symString(6); + startDocument(); + break; + } - case 13: - hasExternalDtdSubset = true; - dtdSystemId = symString(2); - break; + case 13: { + hasExternalDtdSubset = true; + dtdSystemId = symString(2); + break; + } - case 14: - checkPublicLiteral(symString(2)); - dtdPublicId = symString(2); - dtdSystemId = symString(4); - hasExternalDtdSubset = true; - break; + case 14: { + checkPublicLiteral(symString(2)); + dtdPublicId = symString(2); + dtdSystemId = symString(4); + hasExternalDtdSubset = true; + break; + } - case 16: - if (!scanPublicOrSystem() && atEnd) { - resume(16); - return false; + case 16: { + if (!scanPublicOrSystem() && atEnd) { + resume(16); + return false; + } + dtdName = symString(3); + break; } - dtdName = symString(3); - break; - case 17: - case 18: - dtdName = symString(3); - // fall through + case 17: + case 18: { + dtdName = symString(3); + // fall through + } - case 19: - case 20: - setType(QXmlStreamReader::DTD); - text = &textBuffer; - break; + case 19: + case 20: { + setType(QXmlStreamReader::DTD); + text = &textBuffer; + break; + } - case 21: - scanDtd = true; - break; + case 21: { + scanDtd = true; + break; + } - case 22: - scanDtd = false; - break; + case 22: { + scanDtd = false; + break; + } - case 37: - if (!scanString(QXmlStreamReader_spell[EMPTY], EMPTY, false) - && !scanString(QXmlStreamReader_spell[ANY], ANY, false) - && atEnd) { - resume(37); - return false; + case 37: { + if (!scanString(QXmlStreamReader_spell[EMPTY], EMPTY, false) + && !scanString(QXmlStreamReader_spell[ANY], ANY, false) + && atEnd) { + resume(37); + return false; + } + break; } - break; - case 43: - if (!scanString(QXmlStreamReader_spell[PCDATA], PCDATA, false) && atEnd) { - resume(43); - return false; + case 43: { + if (!scanString(QXmlStreamReader_spell[PCDATA], PCDATA, false) && atEnd) { + resume(43); + return false; + } + break; } - break; - case 68: { - lastAttributeIsCData = true; - } break; + case 68: { + lastAttributeIsCData = true; + break; + } - case 78: - if (!scanAfterDefaultDecl() && atEnd) { - resume(78); - return false; + case 78: { + if (!scanAfterDefaultDecl() && atEnd) { + resume(78); + return false; + } + break; } - break; - case 83: + case 83: { sym(1) = sym(2); lastAttributeValue.clear(); lastAttributeIsCData = false; @@ -1354,564 +1370,612 @@ bool QXmlStreamReaderPrivate::parse() resume(83); return false; } - break; + break; + } - case 84: { - DtdAttribute &dtdAttribute = dtdAttributes.push(); - dtdAttribute.tagName.clear(); - dtdAttribute.isCDATA = lastAttributeIsCData; - dtdAttribute.attributePrefix = addToStringStorage(symPrefix(1)); - dtdAttribute.attributeName = addToStringStorage(symString(1)); - dtdAttribute.attributeQualifiedName = addToStringStorage(symName(1)); - dtdAttribute.isNamespaceAttribute = (dtdAttribute.attributePrefix == QLatin1String("xmlns") - || (dtdAttribute.attributePrefix.isEmpty() - && dtdAttribute.attributeName == QLatin1String("xmlns"))); - if (lastAttributeValue.isNull()) { - dtdAttribute.defaultValue.clear(); - } else { - if (dtdAttribute.isCDATA) - dtdAttribute.defaultValue = addToStringStorage(lastAttributeValue); - else - dtdAttribute.defaultValue = addToStringStorage(lastAttributeValue.toString().simplified()); + case 84: { + DtdAttribute &dtdAttribute = dtdAttributes.push(); + dtdAttribute.tagName.clear(); + dtdAttribute.isCDATA = lastAttributeIsCData; + dtdAttribute.attributePrefix = addToStringStorage(symPrefix(1)); + dtdAttribute.attributeName = addToStringStorage(symString(1)); + dtdAttribute.attributeQualifiedName = addToStringStorage(symName(1)); + dtdAttribute.isNamespaceAttribute = (dtdAttribute.attributePrefix == QLatin1String("xmlns") + || (dtdAttribute.attributePrefix.isEmpty() + && dtdAttribute.attributeName == QLatin1String("xmlns"))); + if (lastAttributeValue.isNull()) { + dtdAttribute.defaultValue.clear(); + } else { + if (dtdAttribute.isCDATA) + dtdAttribute.defaultValue = addToStringStorage(lastAttributeValue); + else + dtdAttribute.defaultValue = addToStringStorage(lastAttributeValue.toString().simplified()); + } + break; } - } break; - case 88: { - if (referenceToUnparsedEntityDetected && !standalone) - break; - int n = dtdAttributes.size(); - QStringRef tagName = addToStringStorage(symName(3)); - while (n--) { - DtdAttribute &dtdAttribute = dtdAttributes[n]; - if (!dtdAttribute.tagName.isNull()) + case 88: { + if (referenceToUnparsedEntityDetected && !standalone) break; - dtdAttribute.tagName = tagName; - for (int i = 0; i < n; ++i) { - if ((dtdAttributes[i].tagName.isNull() || dtdAttributes[i].tagName == tagName) - && dtdAttributes[i].attributeQualifiedName == dtdAttribute.attributeQualifiedName) { - dtdAttribute.attributeQualifiedName.clear(); // redefined, delete it + int n = dtdAttributes.size(); + QStringRef tagName = addToStringStorage(symName(3)); + while (n--) { + DtdAttribute &dtdAttribute = dtdAttributes[n]; + if (!dtdAttribute.tagName.isNull()) break; + dtdAttribute.tagName = tagName; + for (int i = 0; i < n; ++i) { + if ((dtdAttributes[i].tagName.isNull() || dtdAttributes[i].tagName == tagName) + && dtdAttributes[i].attributeQualifiedName == dtdAttribute.attributeQualifiedName) { + dtdAttribute.attributeQualifiedName.clear(); // redefined, delete it + break; + } } } + break; } - } break; - - case 89: { - if (!scanPublicOrSystem() && atEnd) { - resume(89); - return false; - } - EntityDeclaration &entityDeclaration = entityDeclarations.push(); - entityDeclaration.clear(); - entityDeclaration.name = symString(3); - } break; - - case 90: { - if (!scanPublicOrSystem() && atEnd) { - resume(90); - return false; - } - EntityDeclaration &entityDeclaration = entityDeclarations.push(); - entityDeclaration.clear(); - entityDeclaration.name = symString(5); - entityDeclaration.parameter = true; - } break; - - case 91: { - if (!scanNData() && atEnd) { - resume(91); - return false; - } - EntityDeclaration &entityDeclaration = entityDeclarations.top(); - entityDeclaration.systemId = symString(3); - entityDeclaration.external = true; - } break; - - case 92: { - if (!scanNData() && atEnd) { - resume(92); - return false; - } - EntityDeclaration &entityDeclaration = entityDeclarations.top(); - checkPublicLiteral((entityDeclaration.publicId = symString(3))); - entityDeclaration.systemId = symString(5); - entityDeclaration.external = true; - } break; - - case 93: { - EntityDeclaration &entityDeclaration = entityDeclarations.top(); - entityDeclaration.notationName = symString(3); - if (entityDeclaration.parameter) - raiseWellFormedError(QXmlStream::tr("NDATA in parameter entity declaration.")); - } - //fall through - - case 94: - case 95: { - if (referenceToUnparsedEntityDetected && !standalone) { - entityDeclarations.pop(); - break; - } - EntityDeclaration &entityDeclaration = entityDeclarations.top(); - if (!entityDeclaration.external) - entityDeclaration.value = symString(2); - QString entityName = entityDeclaration.name.toString(); - QHash &hash = entityDeclaration.parameter ? parameterEntityHash : entityHash; - if (!hash.contains(entityName)) { - Entity entity(entityDeclaration.value.toString()); - entity.unparsed = (!entityDeclaration.notationName.isNull()); - entity.external = entityDeclaration.external; - hash.insert(entityName, entity); - } - } break; - - case 96: { - setType(QXmlStreamReader::ProcessingInstruction); - int pos = sym(4).pos + sym(4).len; - processingInstructionTarget = symString(3); - if (scanUntil("?>")) { - processingInstructionData = QStringRef(&textBuffer, pos, textBuffer.size() - pos - 2); - const QString piTarget(processingInstructionTarget.toString()); - if (!piTarget.compare(QLatin1String("xml"), Qt::CaseInsensitive)) { - raiseWellFormedError(QXmlStream::tr("XML declaration not at start of document.")); + + case 89: { + if (!scanPublicOrSystem() && atEnd) { + resume(89); + return false; } - else if(!QXmlUtils::isNCName(piTarget)) - raiseWellFormedError(QXmlStream::tr("%1 is an invalid processing instruction name.").arg(piTarget)); - } else if (type != QXmlStreamReader::Invalid){ - resume(96); - return false; - } - } break; - - case 97: - setType(QXmlStreamReader::ProcessingInstruction); - processingInstructionTarget = symString(3); - if (!processingInstructionTarget.toString().compare(QLatin1String("xml"), Qt::CaseInsensitive)) - raiseWellFormedError(QXmlStream::tr("Invalid processing instruction name.")); - break; + EntityDeclaration &entityDeclaration = entityDeclarations.push(); + entityDeclaration.clear(); + entityDeclaration.name = symString(3); + break; + } - case 98: - if (!scanAfterLangleBang() && atEnd) { - resume(98); - return false; + case 90: { + if (!scanPublicOrSystem() && atEnd) { + resume(90); + return false; + } + EntityDeclaration &entityDeclaration = entityDeclarations.push(); + entityDeclaration.clear(); + entityDeclaration.name = symString(5); + entityDeclaration.parameter = true; + break; } - break; - case 99: - if (!scanUntil("--")) { - resume(99); - return false; + case 91: { + if (!scanNData() && atEnd) { + resume(91); + return false; + } + EntityDeclaration &entityDeclaration = entityDeclarations.top(); + entityDeclaration.systemId = symString(3); + entityDeclaration.external = true; + break; } - break; - case 100: { - setType(QXmlStreamReader::Comment); - int pos = sym(1).pos + 4; - text = QStringRef(&textBuffer, pos, textBuffer.size() - pos - 3); - } break; - - case 101: { - setType(QXmlStreamReader::Characters); - isCDATA = true; - isWhitespace = false; - int pos = sym(2).pos; - if (scanUntil("]]>", -1)) { - text = QStringRef(&textBuffer, pos, textBuffer.size() - pos - 3); - } else { - resume(101); - return false; - } - } break; - - case 102: { - if (!scanPublicOrSystem() && atEnd) { - resume(102); - return false; - } - NotationDeclaration ¬ationDeclaration = notationDeclarations.push(); - notationDeclaration.name = symString(3); - } break; - - case 103: { - NotationDeclaration ¬ationDeclaration = notationDeclarations.top(); - notationDeclaration.systemId = symString(3); - notationDeclaration.publicId.clear(); - } break; - - case 104: { - NotationDeclaration ¬ationDeclaration = notationDeclarations.top(); - notationDeclaration.systemId.clear(); - checkPublicLiteral((notationDeclaration.publicId = symString(3))); - } break; - - case 105: { - NotationDeclaration ¬ationDeclaration = notationDeclarations.top(); - checkPublicLiteral((notationDeclaration.publicId = symString(3))); - notationDeclaration.systemId = symString(5); - } break; - - case 129: - isWhitespace = false; - // fall through - - case 130: - sym(1).len += fastScanContentCharList(); - if (atEnd && !inParseEntity) { - resume(130); - return false; + case 92: { + if (!scanNData() && atEnd) { + resume(92); + return false; + } + EntityDeclaration &entityDeclaration = entityDeclarations.top(); + checkPublicLiteral((entityDeclaration.publicId = symString(3))); + entityDeclaration.systemId = symString(5); + entityDeclaration.external = true; + break; } - break; - case 139: - if (!textBuffer.isEmpty()) { - setType(QXmlStreamReader::Characters); - text = &textBuffer; + case 93: { + EntityDeclaration &entityDeclaration = entityDeclarations.top(); + entityDeclaration.notationName = symString(3); + if (entityDeclaration.parameter) + raiseWellFormedError(QXmlStream::tr("NDATA in parameter entity declaration.")); + //fall through } - break; - case 140: - case 141: - clearSym(); - break; + case 94: + case 95: { + if (referenceToUnparsedEntityDetected && !standalone) { + entityDeclarations.pop(); + break; + } + EntityDeclaration &entityDeclaration = entityDeclarations.top(); + if (!entityDeclaration.external) + entityDeclaration.value = symString(2); + QString entityName = entityDeclaration.name.toString(); + QHash &hash = entityDeclaration.parameter ? parameterEntityHash : entityHash; + if (!hash.contains(entityName)) { + Entity entity(entityDeclaration.value.toString()); + entity.unparsed = (!entityDeclaration.notationName.isNull()); + entity.external = entityDeclaration.external; + hash.insert(entityName, entity); + } + break; + } - case 142: - case 143: - sym(1) = sym(2); - break; + case 96: { + setType(QXmlStreamReader::ProcessingInstruction); + int pos = sym(4).pos + sym(4).len; + processingInstructionTarget = symString(3); + if (scanUntil("?>")) { + processingInstructionData = QStringRef(&textBuffer, pos, textBuffer.size() - pos - 2); + const QString piTarget(processingInstructionTarget.toString()); + if (!piTarget.compare(QLatin1String("xml"), Qt::CaseInsensitive)) { + raiseWellFormedError(QXmlStream::tr("XML declaration not at start of document.")); + } + else if(!QXmlUtils::isNCName(piTarget)) + raiseWellFormedError(QXmlStream::tr("%1 is an invalid processing instruction name.").arg(piTarget)); + } else if (type != QXmlStreamReader::Invalid){ + resume(96); + return false; + } + break; + } - case 144: - case 145: - case 146: - case 147: - sym(1).len += sym(2).len; - break; + case 97: { + setType(QXmlStreamReader::ProcessingInstruction); + processingInstructionTarget = symString(3); + if (!processingInstructionTarget.toString().compare(QLatin1String("xml"), Qt::CaseInsensitive)) + raiseWellFormedError(QXmlStream::tr("Invalid processing instruction name.")); + break; + } - case 173: - if (normalizeLiterals) - textBuffer.data()[textBuffer.size()-1] = QLatin1Char(' '); - break; + case 98: { + if (!scanAfterLangleBang() && atEnd) { + resume(98); + return false; + } + break; + } - case 174: - sym(1).len += fastScanLiteralContent(); - if (atEnd) { - resume(174); - return false; + case 99: { + if (!scanUntil("--")) { + resume(99); + return false; + } + break; } - break; - case 175: { - if (!QXmlUtils::isPublicID(symString(1).toString())) { - raiseWellFormedError(QXmlStream::tr("%1 is an invalid PUBLIC identifier.").arg(symString(1).toString())); - resume(175); - return false; + case 100: { + setType(QXmlStreamReader::Comment); + int pos = sym(1).pos + 4; + text = QStringRef(&textBuffer, pos, textBuffer.size() - pos - 3); + break; } - } break; - case 176: - case 177: - clearSym(); - break; + case 101: { + setType(QXmlStreamReader::Characters); + isCDATA = true; + isWhitespace = false; + int pos = sym(2).pos; + if (scanUntil("]]>", -1)) { + text = QStringRef(&textBuffer, pos, textBuffer.size() - pos - 3); + } else { + resume(101); + return false; + } + break; + } - case 178: - case 179: - sym(1) = sym(2); - break; + case 102: { + if (!scanPublicOrSystem() && atEnd) { + resume(102); + return false; + } + NotationDeclaration ¬ationDeclaration = notationDeclarations.push(); + notationDeclaration.name = symString(3); + break; + } - case 180: - case 181: - case 182: - case 183: - sym(1).len += sym(2).len; - break; + case 103: { + NotationDeclaration ¬ationDeclaration = notationDeclarations.top(); + notationDeclaration.systemId = symString(3); + notationDeclaration.publicId.clear(); + break; + } - case 213: - case 214: - clearSym(); - break; + case 104: { + NotationDeclaration ¬ationDeclaration = notationDeclarations.top(); + notationDeclaration.systemId.clear(); + checkPublicLiteral((notationDeclaration.publicId = symString(3))); + break; + } - case 215: - case 216: - sym(1) = sym(2); - lastAttributeValue = symString(1); - break; + case 105: { + NotationDeclaration ¬ationDeclaration = notationDeclarations.top(); + checkPublicLiteral((notationDeclaration.publicId = symString(3))); + notationDeclaration.systemId = symString(5); + break; + } - case 217: - case 218: - case 219: - case 220: - sym(1).len += sym(2).len; - break; + case 129: { + isWhitespace = false; + // fall through + } - case 229: { - QStringRef prefix = symPrefix(1); - if (prefix.isEmpty() && symString(1) == QLatin1String("xmlns") && namespaceProcessing) { - NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push(); - namespaceDeclaration.prefix.clear(); + case 130: { + sym(1).len += fastScanContentCharList(); + if (atEnd && !inParseEntity) { + resume(130); + return false; + } + break; + } - const QStringRef ns(symString(5)); - if(ns == QLatin1String("http://www.w3.org/2000/xmlns/") || - ns == QLatin1String("http://www.w3.org/XML/1998/namespace")) - raiseWellFormedError(QXmlStream::tr("Illegal namespace declaration.")); - else - namespaceDeclaration.namespaceUri = addToStringStorage(ns); - } else { - Attribute &attribute = attributeStack.push(); - attribute.key = sym(1); - attribute.value = sym(5); - - QStringRef attributeQualifiedName = symName(1); - bool normalize = false; - for (int a = 0; a < dtdAttributes.size(); ++a) { - DtdAttribute &dtdAttribute = dtdAttributes[a]; - if (!dtdAttribute.isCDATA - && dtdAttribute.tagName == qualifiedName - && dtdAttribute.attributeQualifiedName == attributeQualifiedName - ) { - normalize = true; - break; - } + case 139: { + if (!textBuffer.isEmpty()) { + setType(QXmlStreamReader::Characters); + text = &textBuffer; } - if (normalize) { - // normalize attribute value (simplify and trim) - int pos = textBuffer.size(); - int n = 0; - bool wasSpace = true; - for (int i = 0; i < attribute.value.len; ++i) { - QChar c = textBuffer.at(attribute.value.pos + i); - if (c.unicode() == ' ') { - if (wasSpace) - continue; - wasSpace = true; - } else { - wasSpace = false; - } - textBuffer += textBuffer.at(attribute.value.pos + i); - ++n; - } - if (wasSpace) - while (n && textBuffer.at(pos + n - 1).unicode() == ' ') - --n; - attribute.value.pos = pos; - attribute.value.len = n; + break; + } + + case 140: + case 141: { + clearSym(); + break; + } + + case 142: + case 143: { + sym(1) = sym(2); + break; + } + + case 144: + case 145: + case 146: + case 147: { + sym(1).len += sym(2).len; + break; + } + + case 173: { + if (normalizeLiterals) + textBuffer.data()[textBuffer.size()-1] = QLatin1Char(' '); + break; + } + + case 174: { + sym(1).len += fastScanLiteralContent(); + if (atEnd) { + resume(174); + return false; } - if (prefix == QLatin1String("xmlns") && namespaceProcessing) { - NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push(); - QStringRef namespacePrefix = symString(attribute.key); - QStringRef namespaceUri = symString(attribute.value); - attributeStack.pop(); - if (((namespacePrefix == QLatin1String("xml")) - ^ (namespaceUri == QLatin1String("http://www.w3.org/XML/1998/namespace"))) - || namespaceUri == QLatin1String("http://www.w3.org/2000/xmlns/") - || namespaceUri.isEmpty() - || namespacePrefix == QLatin1String("xmlns")) - raiseWellFormedError(QXmlStream::tr("Illegal namespace declaration.")); + break; + } - namespaceDeclaration.prefix = addToStringStorage(namespacePrefix); - namespaceDeclaration.namespaceUri = addToStringStorage(namespaceUri); + case 175: { + if (!QXmlUtils::isPublicID(symString(1).toString())) { + raiseWellFormedError(QXmlStream::tr("%1 is an invalid PUBLIC identifier.").arg(symString(1).toString())); + resume(175); + return false; } + break; } - } break; - case 235: { - normalizeLiterals = true; - Tag &tag = tagStack_push(); - prefix = tag.namespaceDeclaration.prefix = addToStringStorage(symPrefix(2)); - name = tag.name = addToStringStorage(symString(2)); - qualifiedName = tag.qualifiedName = addToStringStorage(symName(2)); - if ((!prefix.isEmpty() && !QXmlUtils::isNCName(prefix)) || !QXmlUtils::isNCName(name)) - raiseWellFormedError(QXmlStream::tr("Invalid XML name.")); - } break; + case 176: + case 177: { + clearSym(); + break; + } - case 236: - isEmptyElement = true; - // fall through + case 178: + case 179: { + sym(1) = sym(2); + break; + } - case 237: - setType(QXmlStreamReader::StartElement); - resolveTag(); - if (tagStack.size() == 1 && hasSeenTag && !inParseEntity) - raiseWellFormedError(QXmlStream::tr("Extra content at end of document.")); - hasSeenTag = true; - break; + case 180: + case 181: + case 182: + case 183: { + sym(1).len += sym(2).len; + break; + } - case 238: { - setType(QXmlStreamReader::EndElement); - Tag &tag = tagStack_pop(); + case 213: + case 214: { + clearSym(); + break; + } - namespaceUri = tag.namespaceDeclaration.namespaceUri; - name = tag.name; - qualifiedName = tag.qualifiedName; - if (qualifiedName != symName(3)) - raiseWellFormedError(QXmlStream::tr("Opening and ending tag mismatch.")); - } break; + case 215: + case 216: { + sym(1) = sym(2); + lastAttributeValue = symString(1); + break; + } - case 239: - if (entitiesMustBeDeclared()) { - raiseWellFormedError(QXmlStream::tr("Entity '%1' not declared.").arg(unresolvedEntity)); + case 217: + case 218: + case 219: + case 220: { + sym(1).len += sym(2).len; break; } - setType(QXmlStreamReader::EntityReference); - name = &unresolvedEntity; - break; - case 240: { - sym(1).len += sym(2).len + 1; - QString reference = symString(2).toString(); - if (entityHash.contains(reference)) { - Entity &entity = entityHash[reference]; - if (entity.unparsed) { - raiseWellFormedError(QXmlStream::tr("Reference to unparsed entity '%1'.").arg(reference)); + case 229: { + QStringRef prefix = symPrefix(1); + if (prefix.isEmpty() && symString(1) == QLatin1String("xmlns") && namespaceProcessing) { + NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push(); + namespaceDeclaration.prefix.clear(); + + const QStringRef ns(symString(5)); + if(ns == QLatin1String("http://www.w3.org/2000/xmlns/") || + ns == QLatin1String("http://www.w3.org/XML/1998/namespace")) + raiseWellFormedError(QXmlStream::tr("Illegal namespace declaration.")); + else + namespaceDeclaration.namespaceUri = addToStringStorage(ns); } else { - if (!entity.hasBeenParsed) { - parseEntity(entity.value); - entity.hasBeenParsed = true; + Attribute &attribute = attributeStack.push(); + attribute.key = sym(1); + attribute.value = sym(5); + + QStringRef attributeQualifiedName = symName(1); + bool normalize = false; + for (int a = 0; a < dtdAttributes.size(); ++a) { + DtdAttribute &dtdAttribute = dtdAttributes[a]; + if (!dtdAttribute.isCDATA + && dtdAttribute.tagName == qualifiedName + && dtdAttribute.attributeQualifiedName == attributeQualifiedName + ) { + normalize = true; + break; + } + } + if (normalize) { + // normalize attribute value (simplify and trim) + int pos = textBuffer.size(); + int n = 0; + bool wasSpace = true; + for (int i = 0; i < attribute.value.len; ++i) { + QChar c = textBuffer.at(attribute.value.pos + i); + if (c.unicode() == ' ') { + if (wasSpace) + continue; + wasSpace = true; + } else { + wasSpace = false; + } + textBuffer += textBuffer.at(attribute.value.pos + i); + ++n; + } + if (wasSpace) + while (n && textBuffer.at(pos + n - 1).unicode() == ' ') + --n; + attribute.value.pos = pos; + attribute.value.len = n; + } + if (prefix == QLatin1String("xmlns") && namespaceProcessing) { + NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push(); + QStringRef namespacePrefix = symString(attribute.key); + QStringRef namespaceUri = symString(attribute.value); + attributeStack.pop(); + if (((namespacePrefix == QLatin1String("xml")) + ^ (namespaceUri == QLatin1String("http://www.w3.org/XML/1998/namespace"))) + || namespaceUri == QLatin1String("http://www.w3.org/2000/xmlns/") + || namespaceUri.isEmpty() + || namespacePrefix == QLatin1String("xmlns")) + raiseWellFormedError(QXmlStream::tr("Illegal namespace declaration.")); + + namespaceDeclaration.prefix = addToStringStorage(namespacePrefix); + namespaceDeclaration.namespaceUri = addToStringStorage(namespaceUri); } - if (entity.literal) - putStringLiteral(entity.value); - else if (referenceEntity(entity)) - putReplacement(entity.value); - textBuffer.chop(2 + sym(2).len); - clearSym(); } break; } - if (entityResolver) { - QString replacementText = resolveUndeclaredEntity(reference); - if (!replacementText.isNull()) { - putReplacement(replacementText); - textBuffer.chop(2 + sym(2).len); - clearSym(); - break; - } + case 235: { + normalizeLiterals = true; + Tag &tag = tagStack_push(); + prefix = tag.namespaceDeclaration.prefix = addToStringStorage(symPrefix(2)); + name = tag.name = addToStringStorage(symString(2)); + qualifiedName = tag.qualifiedName = addToStringStorage(symName(2)); + if ((!prefix.isEmpty() && !QXmlUtils::isNCName(prefix)) || !QXmlUtils::isNCName(name)) + raiseWellFormedError(QXmlStream::tr("Invalid XML name.")); + break; } - injectToken(UNRESOLVED_ENTITY); - unresolvedEntity = symString(2).toString(); - textBuffer.chop(2 + sym(2).len); - clearSym(); + case 236: { + isEmptyElement = true; + // fall through + } - } break; + case 237: { + setType(QXmlStreamReader::StartElement); + resolveTag(); + if (tagStack.size() == 1 && hasSeenTag && !inParseEntity) + raiseWellFormedError(QXmlStream::tr("Extra content at end of document.")); + hasSeenTag = true; + break; + } - case 241: { - sym(1).len += sym(2).len + 1; - QString reference = symString(2).toString(); - if (parameterEntityHash.contains(reference)) { - referenceToParameterEntityDetected = true; - Entity &entity = parameterEntityHash[reference]; - if (entity.unparsed || entity.external) { - referenceToUnparsedEntityDetected = true; - } else { - if (referenceEntity(entity)) - putString(entity.value); - textBuffer.chop(2 + sym(2).len); - clearSym(); - } - } else if (entitiesMustBeDeclared()) { - raiseWellFormedError(QXmlStream::tr("Entity '%1' not declared.").arg(symString(2).toString())); + case 238: { + setType(QXmlStreamReader::EndElement); + Tag &tag = tagStack_pop(); + + namespaceUri = tag.namespaceDeclaration.namespaceUri; + name = tag.name; + qualifiedName = tag.qualifiedName; + if (qualifiedName != symName(3)) + raiseWellFormedError(QXmlStream::tr("Opening and ending tag mismatch.")); + break; } - } break; - case 242: - sym(1).len += sym(2).len + 1; - break; + case 239: { + if (entitiesMustBeDeclared()) { + raiseWellFormedError(QXmlStream::tr("Entity '%1' not declared.").arg(unresolvedEntity)); + break; + } + setType(QXmlStreamReader::EntityReference); + name = &unresolvedEntity; + break; + } - case 243: { - sym(1).len += sym(2).len + 1; - QString reference = symString(2).toString(); - if (entityHash.contains(reference)) { - Entity &entity = entityHash[reference]; - if (entity.unparsed || entity.value.isNull()) { - raiseWellFormedError(QXmlStream::tr("Reference to external entity '%1' in attribute value.").arg(reference)); + case 240: { + sym(1).len += sym(2).len + 1; + QString reference = symString(2).toString(); + if (entityHash.contains(reference)) { + Entity &entity = entityHash[reference]; + if (entity.unparsed) { + raiseWellFormedError(QXmlStream::tr("Reference to unparsed entity '%1'.").arg(reference)); + } else { + if (!entity.hasBeenParsed) { + parseEntity(entity.value); + entity.hasBeenParsed = true; + } + if (entity.literal) + putStringLiteral(entity.value); + else if (referenceEntity(entity)) + putReplacement(entity.value); + textBuffer.chop(2 + sym(2).len); + clearSym(); + } break; } - if (!entity.hasBeenParsed) { - parseEntity(entity.value); - entity.hasBeenParsed = true; + + if (entityResolver) { + QString replacementText = resolveUndeclaredEntity(reference); + if (!replacementText.isNull()) { + putReplacement(replacementText); + textBuffer.chop(2 + sym(2).len); + clearSym(); + break; + } } - if (entity.literal) - putStringLiteral(entity.value); - else if (referenceEntity(entity)) - putReplacementInAttributeValue(entity.value); + + injectToken(UNRESOLVED_ENTITY); + unresolvedEntity = symString(2).toString(); textBuffer.chop(2 + sym(2).len); clearSym(); break; } - if (entityResolver) { - QString replacementText = resolveUndeclaredEntity(reference); - if (!replacementText.isNull()) { - putReplacement(replacementText); + case 241: { + sym(1).len += sym(2).len + 1; + QString reference = symString(2).toString(); + if (parameterEntityHash.contains(reference)) { + referenceToParameterEntityDetected = true; + Entity &entity = parameterEntityHash[reference]; + if (entity.unparsed || entity.external) { + referenceToUnparsedEntityDetected = true; + } else { + if (referenceEntity(entity)) + putString(entity.value); + textBuffer.chop(2 + sym(2).len); + clearSym(); + } + } else if (entitiesMustBeDeclared()) { + raiseWellFormedError(QXmlStream::tr("Entity '%1' not declared.").arg(symString(2).toString())); + } + break; + } + + case 242: { + sym(1).len += sym(2).len + 1; + break; + } + + case 243: { + sym(1).len += sym(2).len + 1; + QString reference = symString(2).toString(); + if (entityHash.contains(reference)) { + Entity &entity = entityHash[reference]; + if (entity.unparsed || entity.value.isNull()) { + raiseWellFormedError(QXmlStream::tr("Reference to external entity '%1' in attribute value.").arg(reference)); + break; + } + if (!entity.hasBeenParsed) { + parseEntity(entity.value); + entity.hasBeenParsed = true; + } + if (entity.literal) + putStringLiteral(entity.value); + else if (referenceEntity(entity)) + putReplacementInAttributeValue(entity.value); textBuffer.chop(2 + sym(2).len); clearSym(); break; } + + if (entityResolver) { + QString replacementText = resolveUndeclaredEntity(reference); + if (!replacementText.isNull()) { + putReplacement(replacementText); + textBuffer.chop(2 + sym(2).len); + clearSym(); + break; + } + } + if (entitiesMustBeDeclared()) { + raiseWellFormedError(QXmlStream::tr("Entity '%1' not declared.").arg(reference)); + } + break; } - if (entitiesMustBeDeclared()) { - raiseWellFormedError(QXmlStream::tr("Entity '%1' not declared.").arg(reference)); - } - } break; - case 244: { - if (uint s = resolveCharRef(3)) { - if (s >= 0xffff) - putStringLiteral(QString::fromUcs4(&s, 1)); - else - putChar((LETTER << 16) | s); + case 244: { + if (uint s = resolveCharRef(3)) { + if (s >= 0xffff) + putStringLiteral(QString::fromUcs4(&s, 1)); + else + putChar((LETTER << 16) | s); - textBuffer.chop(3 + sym(3).len); - clearSym(); - } else { - raiseWellFormedError(QXmlStream::tr("Invalid character reference.")); + textBuffer.chop(3 + sym(3).len); + clearSym(); + } else { + raiseWellFormedError(QXmlStream::tr("Invalid character reference.")); + } + break; } - } break; - - case 247: - case 248: - sym(1).len += sym(2).len; - break; - case 259: - sym(1).len += fastScanSpace(); - if (atEnd) { - resume(259); - return false; + case 247: + case 248: { + sym(1).len += sym(2).len; + break; } - break; - case 262: { - sym(1).len += fastScanName(&sym(1).prefix); - if (atEnd) { - resume(262); - return false; + case 259: { + sym(1).len += fastScanSpace(); + if (atEnd) { + resume(259); + return false; + } + break; } - } break; - case 263: - sym(1).len += fastScanName(); - if (atEnd) { - resume(263); - return false; + case 262: { + sym(1).len += fastScanName(&sym(1).prefix); + if (atEnd) { + resume(262); + return false; + } + break; } - break; - case 264: - case 265: - case 266: - case 267: - case 268: - sym(1).len += fastScanNMTOKEN(); - if (atEnd) { - resume(268); - return false; + case 263: { + sym(1).len += fastScanName(); + if (atEnd) { + resume(263); + return false; + } + break; } - break; + case 264: + case 265: + case 266: + case 267: + case 268: { + sym(1).len += fastScanNMTOKEN(); + if (atEnd) { + resume(268); + return false; + } - default: - ; - } // switch + break; + } + + default: + ; + } // switch act = state_stack[tos] = nt_action (act, QXmlStreamReader_lhs[r] - TERMINAL_COUNT); if (type != QXmlStreamReader::NoToken) return true; -- 2.11.0