dbertoni 2002/07/24 16:20:48 Modified: c/src/XSLT XSLTEngineImpl.cpp XSLTEngineImpl.hpp Log: Use empty() instead of size(). Cache flag that indicates the presence of CDATA section elements for output. Fixed bug where stack was not being popped properly. Revision Changes Path 1.151 +72 -79 xml-xalan/c/src/XSLT/XSLTEngineImpl.cpp Index: XSLTEngineImpl.cpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/XSLT/XSLTEngineImpl.cpp,v retrieving revision 1.150 retrieving revision 1.151 diff -u -r1.150 -r1.151 --- XSLTEngineImpl.cpp 11 Jul 2002 05:15:13 -0000 1.150 +++ XSLTEngineImpl.cpp 24 Jul 2002 23:20:48 -0000 1.151 @@ -195,9 +195,10 @@ m_resultNamespacesStack(), m_dummyAttributesList(), m_scratchString(), - m_hasStripOrPreserveSpace(false), m_attributeNamesVisited(), - m_attributeNamesVisitedEnd(m_attributeNamesVisited.end()) + m_attributeNamesVisitedEnd(m_attributeNamesVisited.end()), + m_hasStripOrPreserveSpace(false), + m_hasCDATASectionElements(false) { m_outputContextStack.pushContext(); } @@ -231,9 +232,10 @@ m_resultNamespacesStack.clear(); - m_hasStripOrPreserveSpace = false; - m_attributeNamesVisited.clear(); + + m_hasStripOrPreserveSpace = false; + m_hasCDATASectionElements = false; } @@ -384,8 +386,10 @@ theFormatter->setPrefixResolver(this); } - m_hasStripOrPreserveSpace = m_stylesheetRoot->getWhitespacePreservingElements().size() > 0 || - m_stylesheetRoot->getWhitespaceStrippingElements().size() > 0; + m_hasStripOrPreserveSpace = m_stylesheetRoot->getWhitespacePreservingElements().empty() == false || + m_stylesheetRoot->getWhitespaceStrippingElements().empty() == false; + + m_hasCDATASectionElements = m_stylesheetRoot->hasCDATASectionElements(); m_stylesheetRoot->process(sourceTree, outputTarget, executionContext); } @@ -428,8 +432,10 @@ theFormatter->setPrefixResolver(this); } - m_hasStripOrPreserveSpace = m_stylesheetRoot->getWhitespacePreservingElements().size() > 0 || - m_stylesheetRoot->getWhitespaceStrippingElements().size() > 0; + m_hasStripOrPreserveSpace = m_stylesheetRoot->getWhitespacePreservingElements().empty() == false || + m_stylesheetRoot->getWhitespaceStrippingElements().empty() == false; + + m_hasCDATASectionElements = m_stylesheetRoot->hasCDATASectionElements(); m_stylesheetRoot->process(sourceTree, outputTarget, executionContext); } @@ -1572,6 +1578,7 @@ { assert(getFormatterListener() != 0); assert(m_executionContext != 0); + assert(m_cdataStack.empty() == true); if (getHasPendingStartDocument() == false) { @@ -1605,6 +1612,7 @@ { assert(getFormatterListener() != 0); assert(m_executionContext != 0); + assert(m_cdataStack.empty() == true); setMustFlushPendingStartDocument(true); @@ -1621,7 +1629,7 @@ m_resultNamespacesStack.popContext(); - assert(m_resultNamespacesStack.size() == 0); + assert(m_resultNamespacesStack.empty() == true); } @@ -1793,7 +1801,10 @@ assert(getFormatterListener() != 0); assert(m_executionContext != 0); - m_cdataStack.push_back(isCDataResultElem(thePendingElementName) ? true : false); + if(m_hasCDATASectionElements == true) + { + m_cdataStack.push_back(isCDataResultElem(thePendingElementName)); + } AttributeListImpl& thePendingAttributes = getPendingAttributesImpl(); @@ -1847,7 +1858,7 @@ const unsigned int nAtts = atts.getLength(); - assert(m_outputContextStack.size() > 0); + assert(m_outputContextStack.empty() == false); AttributeListImpl& thePendingAttributes = getPendingAttributesImpl(); @@ -1888,8 +1899,10 @@ m_resultNamespacesStack.popContext(); - if(m_stylesheetRoot->hasCDATASectionElements() == true) + if(m_hasCDATASectionElements == true) { + assert(m_cdataStack.empty() == false); + m_cdataStack.pop_back(); } } @@ -1916,6 +1929,7 @@ { assert(getFormatterListener() != 0); assert(ch != 0); + assert(m_hasCDATASectionElements == m_stylesheetRoot->hasCDATASectionElements()); doFlushPending(); @@ -1945,6 +1959,7 @@ XSLTEngineImpl::characters(const XalanNode& node) { assert(getFormatterListener() != 0); + assert(m_hasCDATASectionElements == m_stylesheetRoot->hasCDATASectionElements()); doFlushPending(); @@ -1975,6 +1990,7 @@ { assert(getFormatterListener() != 0); assert(xobject.null() == false); + assert(m_hasCDATASectionElements == m_stylesheetRoot->hasCDATASectionElements()); doFlushPending(); @@ -2164,30 +2180,14 @@ flushPending(); - if(m_stylesheetRoot->hasCDATASectionElements() == true && - 0 != m_cdataStack.size()) - { - getFormatterListener()->cdata(ch, length); - - if(getTraceListeners() > 0) - { - GenerateEvent ge(GenerateEvent::EVENTTYPE_CDATA, ch, start, - length); + getFormatterListener()->cdata(ch, length); - fireGenerateEvent(ge); - } - } - else + if(getTraceListeners() > 0) { - getFormatterListener()->characters(ch, length); - - if(getTraceListeners() > 0) - { - GenerateEvent ge(GenerateEvent::EVENTTYPE_CHARACTERS, ch, - start, length); + GenerateEvent ge(GenerateEvent::EVENTTYPE_CDATA, ch, start, + length); - fireGenerateEvent(ge); - } + fireGenerateEvent(ge); } } @@ -2242,7 +2242,6 @@ if(!overrideStrip) { stripWhiteSpace = isLiteral ? true : false; - // stripWhiteSpace = isLiteral ? true : shouldStripSourceNode(*m_executionContext, node); } const bool isIgnorableWhitespace = node.isIgnorableWhitespace(); @@ -2690,68 +2689,62 @@ XSLTEngineImpl::isCDataResultElem(const XalanDOMString& elementName) const { assert(m_executionContext != 0); + assert(m_hasCDATASectionElements == true); - if(m_stylesheetRoot->hasCDATASectionElements() == false) - { - return false; - } - else - { - bool fResult = false; + bool fResult = false; - const XalanDOMString::size_type indexOfNSSep = indexOf(elementName, XalanUnicode::charColon); + const XalanDOMString::size_type indexOfNSSep = indexOf(elementName, XalanUnicode::charColon); - if(indexOfNSSep == length(elementName)) - { - const XalanDOMString* const elemNS = + if(indexOfNSSep == length(elementName)) + { + const XalanDOMString* const elemNS = getResultNamespaceForPrefix(s_emptyString); - if (elemNS != 0) - { - fResult = m_stylesheetRoot->isCDATASectionElementName(XalanQNameByReference(*elemNS, elementName)); - } - else - { - fResult = m_stylesheetRoot->isCDATASectionElementName(XalanQNameByReference(s_emptyString, elementName)); - } + if (elemNS != 0) + { + fResult = m_stylesheetRoot->isCDATASectionElementName(XalanQNameByReference(*elemNS, elementName)); } else { - typedef StylesheetExecutionContext::GetAndReleaseCachedString GetAndReleaseCachedString; + fResult = m_stylesheetRoot->isCDATASectionElementName(XalanQNameByReference(s_emptyString, elementName)); + } + } + else + { + typedef StylesheetExecutionContext::GetAndReleaseCachedString GetAndReleaseCachedString; - GetAndReleaseCachedString elemLocalNameGuard(*m_executionContext); - GetAndReleaseCachedString prefixGuard(*m_executionContext); + GetAndReleaseCachedString elemLocalNameGuard(*m_executionContext); + GetAndReleaseCachedString prefixGuard(*m_executionContext); - XalanDOMString& elemLocalName = elemLocalNameGuard.get(); - XalanDOMString& prefix = prefixGuard.get(); + XalanDOMString& elemLocalName = elemLocalNameGuard.get(); + XalanDOMString& prefix = prefixGuard.get(); - substring(elementName, prefix, 0, indexOfNSSep); - substring(elementName, elemLocalName, indexOfNSSep + 1); + substring(elementName, prefix, 0, indexOfNSSep); + substring(elementName, elemLocalName, indexOfNSSep + 1); - if(equals(prefix, DOMServices::s_XMLString)) - { - fResult = + if(equals(prefix, DOMServices::s_XMLString)) + { + fResult = m_stylesheetRoot->isCDATASectionElementName(XalanQNameByReference(DOMServices::s_XMLNamespaceURI, elemLocalName)); + } + else + { + const XalanDOMString* const elemNS = + getResultNamespaceForPrefix(prefix); + + if(elemNS == 0) + { + error("Prefix must resolve to a namespace: " + prefix); } else { - const XalanDOMString* const elemNS = - getResultNamespaceForPrefix(prefix); - - if(elemNS == 0) - { - error("Prefix must resolve to a namespace: " + prefix); - } - else - { - fResult = + fResult = m_stylesheetRoot->isCDATASectionElementName(XalanQNameByReference(*elemNS, elemLocalName)); - } } } - - return fResult; } + + return fResult; } @@ -2993,7 +2986,7 @@ const unsigned int nAttrs = nnm->getLength(); - assert(m_outputContextStack.size() > 0); + assert(m_outputContextStack.empty() == false); AttributeListImpl& thePendingAttributes = getPendingAttributesImpl(); @@ -3162,8 +3155,8 @@ { bool strip = false; - assert(m_stylesheetRoot->getWhitespacePreservingElements().size() > 0 || - m_stylesheetRoot->getWhitespaceStrippingElements().size() > 0); + assert(m_stylesheetRoot->getWhitespacePreservingElements().empty() == false || + m_stylesheetRoot->getWhitespaceStrippingElements().empty() == false); const XalanNode::NodeType type = textNode.getNodeType(); 1.91 +26 -15 xml-xalan/c/src/XSLT/XSLTEngineImpl.hpp Index: XSLTEngineImpl.hpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/XSLT/XSLTEngineImpl.hpp,v retrieving revision 1.90 retrieving revision 1.91 diff -u -r1.90 -r1.91 --- XSLTEngineImpl.hpp 11 Jul 2002 00:36:19 -0000 1.90 +++ XSLTEngineImpl.hpp 24 Jul 2002 23:20:48 -0000 1.91 @@ -468,7 +468,7 @@ const XalanDOMString& aname, const XalanDOMString& value) { - assert(m_outputContextStack.size() > 0); + assert(m_outputContextStack.empty() == false); addResultAttribute(getPendingAttributesImpl(), aname, @@ -931,16 +931,6 @@ diag(const char* s) const; /** - * Tell if a given element name should output it's text - * as cdata. - * - * @param elementName name of element - * @return true if it should output as cdata - */ - bool - isCDataResultElem(const XalanDOMString& elementName) const; - - /** * Retrieve the result namespace corresponding to a prefix. * * @param prefix prefix for namespace @@ -1665,8 +1655,16 @@ bool generateCDATASection() const { - return 0 != m_cdataStack.size() && - m_cdataStack.back() == true; + if (m_hasCDATASectionElements == false) + { + return false; + } + else + { + assert(m_cdataStack.empty() == false); + + return m_cdataStack.back(); + } } void @@ -1677,6 +1675,16 @@ flushPending(); } + /** + * Tell if a given element name should output its text + * as cdata. + * + * @param elementName name of element + * @return true if it should output as cdata + */ + bool + isCDataResultElem(const XalanDOMString& elementName) const; + void fireCharacterGenerateEvent( const XalanNode& theNode, @@ -1732,11 +1740,14 @@ XalanDOMString m_scratchString; - bool m_hasStripOrPreserveSpace; - XalanDOMStringPointerSetType m_attributeNamesVisited; const XalanDOMStringPointerSetType::iterator m_attributeNamesVisitedEnd; + + bool m_hasStripOrPreserveSpace; + + bool m_hasCDATASectionElements; + static void installFunctions();
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]