michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "txExpr.h" michael@0: #include "nsIAtom.h" michael@0: #include "txIXPathContext.h" michael@0: #include "txXPathTreeWalker.h" michael@0: michael@0: bool txNodeTypeTest::matches(const txXPathNode& aNode, michael@0: txIMatchContext* aContext) michael@0: { michael@0: switch (mNodeType) { michael@0: case COMMENT_TYPE: michael@0: { michael@0: return txXPathNodeUtils::isComment(aNode); michael@0: } michael@0: case TEXT_TYPE: michael@0: { michael@0: return txXPathNodeUtils::isText(aNode) && michael@0: !aContext->isStripSpaceAllowed(aNode); michael@0: } michael@0: case PI_TYPE: michael@0: { michael@0: return txXPathNodeUtils::isProcessingInstruction(aNode) && michael@0: (!mNodeName || michael@0: txXPathNodeUtils::localNameEquals(aNode, mNodeName)); michael@0: } michael@0: case NODE_TYPE: michael@0: { michael@0: return !txXPathNodeUtils::isText(aNode) || michael@0: !aContext->isStripSpaceAllowed(aNode); michael@0: } michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: txNodeTest::NodeTestType michael@0: txNodeTypeTest::getType() michael@0: { michael@0: return NODETYPE_TEST; michael@0: } michael@0: michael@0: /* michael@0: * Returns the default priority of this txNodeTest michael@0: */ michael@0: double txNodeTypeTest::getDefaultPriority() michael@0: { michael@0: return mNodeName ? 0 : -0.5; michael@0: } michael@0: michael@0: bool michael@0: txNodeTypeTest::isSensitiveTo(Expr::ContextSensitivity aContext) michael@0: { michael@0: return !!(aContext & Expr::NODE_CONTEXT); michael@0: } michael@0: michael@0: #ifdef TX_TO_STRING michael@0: void michael@0: txNodeTypeTest::toString(nsAString& aDest) michael@0: { michael@0: switch (mNodeType) { michael@0: case COMMENT_TYPE: michael@0: aDest.Append(NS_LITERAL_STRING("comment()")); michael@0: break; michael@0: case TEXT_TYPE: michael@0: aDest.Append(NS_LITERAL_STRING("text()")); michael@0: break; michael@0: case PI_TYPE: michael@0: aDest.AppendLiteral("processing-instruction("); michael@0: if (mNodeName) { michael@0: nsAutoString str; michael@0: mNodeName->ToString(str); michael@0: aDest.Append(char16_t('\'')); michael@0: aDest.Append(str); michael@0: aDest.Append(char16_t('\'')); michael@0: } michael@0: aDest.Append(char16_t(')')); michael@0: break; michael@0: case NODE_TYPE: michael@0: aDest.Append(NS_LITERAL_STRING("node()")); michael@0: break; michael@0: } michael@0: } michael@0: #endif