1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is TransforMiiX XSLT processor code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * IBM Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 2002
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * IBM Corporation
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #include "txExpr.h"
40 :
41 : nsresult
42 0 : txLiteralExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
43 : {
44 0 : NS_ENSURE_TRUE(mValue, NS_ERROR_OUT_OF_MEMORY);
45 :
46 0 : *aResult = mValue;
47 0 : NS_ADDREF(*aResult);
48 :
49 0 : return NS_OK;
50 : }
51 :
52 : static Expr::ResultType resultTypes[] =
53 : {
54 : Expr::NODESET_RESULT, // NODESET
55 : Expr::BOOLEAN_RESULT, // BOOLEAN
56 : Expr::NUMBER_RESULT, // NUMBER
57 : Expr::STRING_RESULT, // STRING
58 : Expr::RTF_RESULT // RESULT_TREE_FRAGMENT
59 : };
60 :
61 : Expr::ResultType
62 0 : txLiteralExpr::getReturnType()
63 : {
64 0 : return resultTypes[mValue->getResultType()];
65 : }
66 :
67 : Expr*
68 0 : txLiteralExpr::getSubExprAt(PRUint32 aPos)
69 : {
70 0 : return nsnull;
71 : }
72 : void
73 0 : txLiteralExpr::setSubExprAt(PRUint32 aPos, Expr* aExpr)
74 : {
75 0 : NS_NOTREACHED("setting bad subexpression index");
76 0 : }
77 :
78 : bool
79 0 : txLiteralExpr::isSensitiveTo(ContextSensitivity aContext)
80 : {
81 0 : return false;
82 : }
83 :
84 : #ifdef TX_TO_STRING
85 : void
86 0 : txLiteralExpr::toString(nsAString& aStr)
87 : {
88 0 : switch (mValue->getResultType()) {
89 : case txAExprResult::NODESET:
90 : {
91 0 : aStr.AppendLiteral(" { Nodeset literal } ");
92 0 : return;
93 : }
94 : case txAExprResult::BOOLEAN:
95 : {
96 0 : if (mValue->booleanValue()) {
97 0 : aStr.AppendLiteral("true()");
98 : }
99 : else {
100 0 : aStr.AppendLiteral("false()");
101 : }
102 0 : return;
103 : }
104 : case txAExprResult::NUMBER:
105 : {
106 0 : txDouble::toString(mValue->numberValue(), aStr);
107 0 : return;
108 : }
109 : case txAExprResult::STRING:
110 : {
111 : StringResult* strRes =
112 : static_cast<StringResult*>(static_cast<txAExprResult*>
113 0 : (mValue));
114 0 : PRUnichar ch = '\'';
115 0 : if (strRes->mValue.FindChar(ch) != kNotFound) {
116 0 : ch = '\"';
117 : }
118 0 : aStr.Append(ch);
119 0 : aStr.Append(strRes->mValue);
120 0 : aStr.Append(ch);
121 0 : return;
122 : }
123 : case txAExprResult::RESULT_TREE_FRAGMENT:
124 : {
125 0 : aStr.AppendLiteral(" { RTF literal } ");
126 0 : return;
127 : }
128 : }
129 : }
130 : #endif
|