Bug 1935611 - Fix libyuv/libpng link failed for loongarch64. r=glandium,tnikkel,ng
[gecko.git] / dom / xslt / xpath / txNodeTypeTest.cpp
blob17d0c604835e8f25fdc7267827b9b3d3221c1658
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "txExpr.h"
7 #include "nsAtom.h"
8 #include "txIXPathContext.h"
9 #include "txXPathTreeWalker.h"
11 nsresult txNodeTypeTest::matches(const txXPathNode& aNode,
12 txIMatchContext* aContext, bool& aMatched) {
13 switch (mNodeType) {
14 case COMMENT_TYPE: {
15 aMatched = txXPathNodeUtils::isComment(aNode);
16 return NS_OK;
18 case TEXT_TYPE: {
19 aMatched = txXPathNodeUtils::isText(aNode);
20 if (aMatched) {
21 bool allowed;
22 nsresult rv = aContext->isStripSpaceAllowed(aNode, allowed);
23 NS_ENSURE_SUCCESS(rv, rv);
25 aMatched = !allowed;
27 return NS_OK;
29 case PI_TYPE: {
30 aMatched =
31 txXPathNodeUtils::isProcessingInstruction(aNode) &&
32 (!mNodeName || txXPathNodeUtils::localNameEquals(aNode, mNodeName));
33 return NS_OK;
35 case NODE_TYPE: {
36 if (txXPathNodeUtils::isText(aNode)) {
37 bool allowed;
38 nsresult rv = aContext->isStripSpaceAllowed(aNode, allowed);
39 NS_ENSURE_SUCCESS(rv, rv);
41 aMatched = !allowed;
42 } else {
43 aMatched = true;
45 return NS_OK;
49 MOZ_ASSERT_UNREACHABLE("Didn't deal with all values of the NodeType enum!");
51 aMatched = false;
52 return NS_OK;
55 txNodeTest::NodeTestType txNodeTypeTest::getType() { return NODETYPE_TEST; }
58 * Returns the default priority of this txNodeTest
60 double txNodeTypeTest::getDefaultPriority() { return mNodeName ? 0 : -0.5; }
62 bool txNodeTypeTest::isSensitiveTo(Expr::ContextSensitivity aContext) {
63 return !!(aContext & Expr::NODE_CONTEXT);
66 #ifdef TX_TO_STRING
67 void txNodeTypeTest::toString(nsAString& aDest) {
68 switch (mNodeType) {
69 case COMMENT_TYPE:
70 aDest.AppendLiteral("comment()");
71 break;
72 case TEXT_TYPE:
73 aDest.AppendLiteral("text()");
74 break;
75 case PI_TYPE:
76 aDest.AppendLiteral("processing-instruction(");
77 if (mNodeName) {
78 nsAutoString str;
79 mNodeName->ToString(str);
80 aDest.Append(char16_t('\''));
81 aDest.Append(str);
82 aDest.Append(char16_t('\''));
84 aDest.Append(char16_t(')'));
85 break;
86 case NODE_TYPE:
87 aDest.AppendLiteral("node()");
88 break;
91 #endif