Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "txExpr.h" |
michael@0 | 7 | |
michael@0 | 8 | nsresult |
michael@0 | 9 | txLiteralExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult) |
michael@0 | 10 | { |
michael@0 | 11 | NS_ENSURE_TRUE(mValue, NS_ERROR_OUT_OF_MEMORY); |
michael@0 | 12 | |
michael@0 | 13 | *aResult = mValue; |
michael@0 | 14 | NS_ADDREF(*aResult); |
michael@0 | 15 | |
michael@0 | 16 | return NS_OK; |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | static Expr::ResultType resultTypes[] = |
michael@0 | 20 | { |
michael@0 | 21 | Expr::NODESET_RESULT, // NODESET |
michael@0 | 22 | Expr::BOOLEAN_RESULT, // BOOLEAN |
michael@0 | 23 | Expr::NUMBER_RESULT, // NUMBER |
michael@0 | 24 | Expr::STRING_RESULT, // STRING |
michael@0 | 25 | Expr::RTF_RESULT // RESULT_TREE_FRAGMENT |
michael@0 | 26 | }; |
michael@0 | 27 | |
michael@0 | 28 | Expr::ResultType |
michael@0 | 29 | txLiteralExpr::getReturnType() |
michael@0 | 30 | { |
michael@0 | 31 | return resultTypes[mValue->getResultType()]; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | Expr* |
michael@0 | 35 | txLiteralExpr::getSubExprAt(uint32_t aPos) |
michael@0 | 36 | { |
michael@0 | 37 | return nullptr; |
michael@0 | 38 | } |
michael@0 | 39 | void |
michael@0 | 40 | txLiteralExpr::setSubExprAt(uint32_t aPos, Expr* aExpr) |
michael@0 | 41 | { |
michael@0 | 42 | NS_NOTREACHED("setting bad subexpression index"); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | bool |
michael@0 | 46 | txLiteralExpr::isSensitiveTo(ContextSensitivity aContext) |
michael@0 | 47 | { |
michael@0 | 48 | return false; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | #ifdef TX_TO_STRING |
michael@0 | 52 | void |
michael@0 | 53 | txLiteralExpr::toString(nsAString& aStr) |
michael@0 | 54 | { |
michael@0 | 55 | switch (mValue->getResultType()) { |
michael@0 | 56 | case txAExprResult::NODESET: |
michael@0 | 57 | { |
michael@0 | 58 | aStr.AppendLiteral(" { Nodeset literal } "); |
michael@0 | 59 | return; |
michael@0 | 60 | } |
michael@0 | 61 | case txAExprResult::BOOLEAN: |
michael@0 | 62 | { |
michael@0 | 63 | if (mValue->booleanValue()) { |
michael@0 | 64 | aStr.AppendLiteral("true()"); |
michael@0 | 65 | } |
michael@0 | 66 | else { |
michael@0 | 67 | aStr.AppendLiteral("false()"); |
michael@0 | 68 | } |
michael@0 | 69 | return; |
michael@0 | 70 | } |
michael@0 | 71 | case txAExprResult::NUMBER: |
michael@0 | 72 | { |
michael@0 | 73 | txDouble::toString(mValue->numberValue(), aStr); |
michael@0 | 74 | return; |
michael@0 | 75 | } |
michael@0 | 76 | case txAExprResult::STRING: |
michael@0 | 77 | { |
michael@0 | 78 | StringResult* strRes = |
michael@0 | 79 | static_cast<StringResult*>(static_cast<txAExprResult*> |
michael@0 | 80 | (mValue)); |
michael@0 | 81 | char16_t ch = '\''; |
michael@0 | 82 | if (strRes->mValue.FindChar(ch) != kNotFound) { |
michael@0 | 83 | ch = '\"'; |
michael@0 | 84 | } |
michael@0 | 85 | aStr.Append(ch); |
michael@0 | 86 | aStr.Append(strRes->mValue); |
michael@0 | 87 | aStr.Append(ch); |
michael@0 | 88 | return; |
michael@0 | 89 | } |
michael@0 | 90 | case txAExprResult::RESULT_TREE_FRAGMENT: |
michael@0 | 91 | { |
michael@0 | 92 | aStr.AppendLiteral(" { RTF literal } "); |
michael@0 | 93 | return; |
michael@0 | 94 | } |
michael@0 | 95 | } |
michael@0 | 96 | } |
michael@0 | 97 | #endif |