dom/xslt/xpath/txLiteralExpr.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     6 #include "txExpr.h"
     8 nsresult
     9 txLiteralExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
    10 {
    11     NS_ENSURE_TRUE(mValue, NS_ERROR_OUT_OF_MEMORY);
    13     *aResult = mValue;
    14     NS_ADDREF(*aResult);
    16     return NS_OK;
    17 }
    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 };
    28 Expr::ResultType
    29 txLiteralExpr::getReturnType()
    30 {
    31     return resultTypes[mValue->getResultType()];
    32 }
    34 Expr*
    35 txLiteralExpr::getSubExprAt(uint32_t aPos)
    36 {
    37     return nullptr;
    38 }
    39 void
    40 txLiteralExpr::setSubExprAt(uint32_t aPos, Expr* aExpr)
    41 {
    42     NS_NOTREACHED("setting bad subexpression index");
    43 }
    45 bool
    46 txLiteralExpr::isSensitiveTo(ContextSensitivity aContext)
    47 {
    48     return false;
    49 }
    51 #ifdef TX_TO_STRING
    52 void
    53 txLiteralExpr::toString(nsAString& aStr)
    54 {
    55     switch (mValue->getResultType()) {
    56         case txAExprResult::NODESET:
    57         {
    58             aStr.AppendLiteral(" { Nodeset literal } ");
    59             return;
    60         }
    61         case txAExprResult::BOOLEAN:
    62         {
    63             if (mValue->booleanValue()) {
    64               aStr.AppendLiteral("true()");
    65             }
    66             else {
    67               aStr.AppendLiteral("false()");
    68             }
    69             return;
    70         }
    71         case txAExprResult::NUMBER:
    72         {
    73             txDouble::toString(mValue->numberValue(), aStr);
    74             return;
    75         }
    76         case txAExprResult::STRING:
    77         {
    78             StringResult* strRes =
    79                 static_cast<StringResult*>(static_cast<txAExprResult*>
    80                                        (mValue));
    81             char16_t ch = '\'';
    82             if (strRes->mValue.FindChar(ch) != kNotFound) {
    83                 ch = '\"';
    84             }
    85             aStr.Append(ch);
    86             aStr.Append(strRes->mValue);
    87             aStr.Append(ch);
    88             return;
    89         }
    90         case txAExprResult::RESULT_TREE_FRAGMENT:
    91         {
    92             aStr.AppendLiteral(" { RTF literal } ");
    93             return;
    94         }
    95     }
    96 }
    97 #endif

mercurial