Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/. */
5 :
6 : #include "txExpr.h"
7 :
8 : nsresult
9 0 : txLiteralExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
10 : {
11 0 : NS_ENSURE_TRUE(mValue, NS_ERROR_OUT_OF_MEMORY);
12 :
13 0 : *aResult = mValue;
14 0 : NS_ADDREF(*aResult);
15 :
16 0 : return NS_OK;
17 : }
18 :
19 : static Expr::ResultType resultTypes[] =
20 : {
21 : Expr::NODESET_RESULT, // NODESET
22 : Expr::BOOLEAN_RESULT, // BOOLEAN
23 : Expr::NUMBER_RESULT, // NUMBER
24 : Expr::STRING_RESULT, // STRING
25 : Expr::RTF_RESULT // RESULT_TREE_FRAGMENT
26 : };
27 :
28 : Expr::ResultType
29 0 : txLiteralExpr::getReturnType()
30 : {
31 0 : return resultTypes[mValue->getResultType()];
32 : }
33 :
34 : Expr*
35 0 : txLiteralExpr::getSubExprAt(uint32_t aPos)
36 : {
37 0 : return nullptr;
38 : }
39 : void
40 0 : txLiteralExpr::setSubExprAt(uint32_t aPos, Expr* aExpr)
41 : {
42 0 : NS_NOTREACHED("setting bad subexpression index");
43 0 : }
44 :
45 : bool
46 0 : txLiteralExpr::isSensitiveTo(ContextSensitivity aContext)
47 : {
48 0 : return false;
49 : }
50 :
51 : #ifdef TX_TO_STRING
52 : void
53 0 : txLiteralExpr::toString(nsAString& aStr)
54 : {
55 0 : switch (mValue->getResultType()) {
56 : case txAExprResult::NODESET:
57 : {
58 0 : aStr.AppendLiteral(" { Nodeset literal } ");
59 0 : return;
60 : }
61 : case txAExprResult::BOOLEAN:
62 : {
63 0 : if (mValue->booleanValue()) {
64 0 : aStr.AppendLiteral("true()");
65 : }
66 : else {
67 0 : aStr.AppendLiteral("false()");
68 : }
69 0 : return;
70 : }
71 : case txAExprResult::NUMBER:
72 : {
73 0 : txDouble::toString(mValue->numberValue(), aStr);
74 0 : return;
75 : }
76 : case txAExprResult::STRING:
77 : {
78 : StringResult* strRes =
79 0 : static_cast<StringResult*>(static_cast<txAExprResult*>
80 0 : (mValue));
81 0 : char16_t ch = '\'';
82 0 : if (strRes->mValue.Contains(ch)) {
83 0 : ch = '\"';
84 : }
85 0 : aStr.Append(ch);
86 0 : aStr.Append(strRes->mValue);
87 0 : aStr.Append(ch);
88 0 : return;
89 : }
90 : case txAExprResult::RESULT_TREE_FRAGMENT:
91 : {
92 0 : aStr.AppendLiteral(" { RTF literal } ");
93 0 : return;
94 : }
95 : }
96 : }
97 : #endif
|