1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/xslt/xpath/txNodeTypeTest.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "txExpr.h" 1.10 +#include "nsIAtom.h" 1.11 +#include "txIXPathContext.h" 1.12 +#include "txXPathTreeWalker.h" 1.13 + 1.14 +bool txNodeTypeTest::matches(const txXPathNode& aNode, 1.15 + txIMatchContext* aContext) 1.16 +{ 1.17 + switch (mNodeType) { 1.18 + case COMMENT_TYPE: 1.19 + { 1.20 + return txXPathNodeUtils::isComment(aNode); 1.21 + } 1.22 + case TEXT_TYPE: 1.23 + { 1.24 + return txXPathNodeUtils::isText(aNode) && 1.25 + !aContext->isStripSpaceAllowed(aNode); 1.26 + } 1.27 + case PI_TYPE: 1.28 + { 1.29 + return txXPathNodeUtils::isProcessingInstruction(aNode) && 1.30 + (!mNodeName || 1.31 + txXPathNodeUtils::localNameEquals(aNode, mNodeName)); 1.32 + } 1.33 + case NODE_TYPE: 1.34 + { 1.35 + return !txXPathNodeUtils::isText(aNode) || 1.36 + !aContext->isStripSpaceAllowed(aNode); 1.37 + } 1.38 + } 1.39 + return true; 1.40 +} 1.41 + 1.42 +txNodeTest::NodeTestType 1.43 +txNodeTypeTest::getType() 1.44 +{ 1.45 + return NODETYPE_TEST; 1.46 +} 1.47 + 1.48 +/* 1.49 + * Returns the default priority of this txNodeTest 1.50 + */ 1.51 +double txNodeTypeTest::getDefaultPriority() 1.52 +{ 1.53 + return mNodeName ? 0 : -0.5; 1.54 +} 1.55 + 1.56 +bool 1.57 +txNodeTypeTest::isSensitiveTo(Expr::ContextSensitivity aContext) 1.58 +{ 1.59 + return !!(aContext & Expr::NODE_CONTEXT); 1.60 +} 1.61 + 1.62 +#ifdef TX_TO_STRING 1.63 +void 1.64 +txNodeTypeTest::toString(nsAString& aDest) 1.65 +{ 1.66 + switch (mNodeType) { 1.67 + case COMMENT_TYPE: 1.68 + aDest.Append(NS_LITERAL_STRING("comment()")); 1.69 + break; 1.70 + case TEXT_TYPE: 1.71 + aDest.Append(NS_LITERAL_STRING("text()")); 1.72 + break; 1.73 + case PI_TYPE: 1.74 + aDest.AppendLiteral("processing-instruction("); 1.75 + if (mNodeName) { 1.76 + nsAutoString str; 1.77 + mNodeName->ToString(str); 1.78 + aDest.Append(char16_t('\'')); 1.79 + aDest.Append(str); 1.80 + aDest.Append(char16_t('\'')); 1.81 + } 1.82 + aDest.Append(char16_t(')')); 1.83 + break; 1.84 + case NODE_TYPE: 1.85 + aDest.Append(NS_LITERAL_STRING("node()")); 1.86 + break; 1.87 + } 1.88 +} 1.89 +#endif