1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3
* The contents of this file are subject to the Mozilla Public
4
* License Version 1.1 (the "License"); you may not use this file
5
* except in compliance with the License. You may obtain a copy of
6
* the License at http://www.mozilla.org/MPL/
8
* Software distributed under the License is distributed on an "AS
9
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
* implied. See the License for the specific language governing
11
* rights and limitations under the License.
13
* The Original Code is TransforMiiX XSLT processor.
15
* The Initial Developer of the Original Code is The MITRE Corporation.
16
* Portions created by MITRE are Copyright (C) 1999 The MITRE Corporation.
18
* Portions created by Keith Visco as a Non MITRE employee,
19
* (C) 1999 Keith Visco. All Rights Reserved.
22
* Keith Visco, kvisco@ziplink.net
25
* Marina Mechtcheriakova, mmarina@mindspring.com
26
* -- added lang() implementation
30
#include "ExprResult.h"
31
#include "FunctionLib.h"
32
#include "nsReadableUtils.h"
34
#include "txIXPathContext.h"
35
#include "txStringUtils.h"
36
#include "txXPathTreeWalker.h"
39
* Creates a default BooleanFunctionCall, which always evaluates to False
41
BooleanFunctionCall::BooleanFunctionCall(BooleanFunctions aType)
47
* Evaluates this Expr based on the given context node and processor state
48
* @param context the context node for evaluation of this Expr
49
* @param ps the ContextState containing the stack information needed
51
* @return the result of the evaluation
54
BooleanFunctionCall::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
58
txListIterator iter(¶ms);
62
if (!requireParams(1, 1, aContext))
63
return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT;
65
aContext->recycler()->getBoolResult(
66
evaluateToBoolean((Expr*)iter.next(), aContext), aResult);
72
if (!requireParams(1, 1, aContext))
73
return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT;
75
txXPathTreeWalker walker(aContext->getContextNode());
80
found = walker.getAttr(txXMLAtoms::lang, kNameSpaceID_XML,
82
} while (!found && walker.moveToParent());
85
aContext->recycler()->getBoolResult(PR_FALSE, aResult);
91
evaluateToString((Expr*)iter.next(), aContext, arg);
92
PRBool result = arg.Equals(Substring(lang, 0, arg.Length()),
93
txCaseInsensitiveStringComparator()) &&
94
(lang.Length() == arg.Length() ||
95
lang.CharAt(arg.Length()) == '-');
97
aContext->recycler()->getBoolResult(result, aResult);
103
if (!requireParams(1, 1, aContext))
104
return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT;
106
aContext->recycler()->getBoolResult(
107
!evaluateToBoolean((Expr*)iter.next(), aContext), aResult);
113
if (!requireParams(0, 0, aContext))
114
return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT;
116
aContext->recycler()->getBoolResult(PR_TRUE, aResult);
122
if (!requireParams(0, 0, aContext))
123
return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT;
125
aContext->recycler()->getBoolResult(PR_FALSE, aResult);
131
aContext->receiveError(NS_LITERAL_STRING("Internal error"),
132
NS_ERROR_UNEXPECTED);
133
return NS_ERROR_UNEXPECTED;
136
nsresult BooleanFunctionCall::getNameAtom(nsIAtom** aAtom)
141
*aAtom = txXPathAtoms::boolean;
146
*aAtom = txXPathAtoms::lang;
151
*aAtom = txXPathAtoms::_not;
156
*aAtom = txXPathAtoms::_true;
161
*aAtom = txXPathAtoms::_false;
167
return NS_ERROR_FAILURE;