dom/xslt/xpath/txLiteralExpr.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/xslt/xpath/txLiteralExpr.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,97 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "txExpr.h"
    1.10 +
    1.11 +nsresult
    1.12 +txLiteralExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
    1.13 +{
    1.14 +    NS_ENSURE_TRUE(mValue, NS_ERROR_OUT_OF_MEMORY);
    1.15 +
    1.16 +    *aResult = mValue;
    1.17 +    NS_ADDREF(*aResult);
    1.18 +
    1.19 +    return NS_OK;
    1.20 +}
    1.21 +
    1.22 +static Expr::ResultType resultTypes[] =
    1.23 +{
    1.24 +    Expr::NODESET_RESULT, // NODESET
    1.25 +    Expr::BOOLEAN_RESULT, // BOOLEAN
    1.26 +    Expr::NUMBER_RESULT,  // NUMBER
    1.27 +    Expr::STRING_RESULT,  // STRING
    1.28 +    Expr::RTF_RESULT      // RESULT_TREE_FRAGMENT
    1.29 +};
    1.30 +
    1.31 +Expr::ResultType
    1.32 +txLiteralExpr::getReturnType()
    1.33 +{
    1.34 +    return resultTypes[mValue->getResultType()];
    1.35 +}
    1.36 +
    1.37 +Expr*
    1.38 +txLiteralExpr::getSubExprAt(uint32_t aPos)
    1.39 +{
    1.40 +    return nullptr;
    1.41 +}
    1.42 +void
    1.43 +txLiteralExpr::setSubExprAt(uint32_t aPos, Expr* aExpr)
    1.44 +{
    1.45 +    NS_NOTREACHED("setting bad subexpression index");
    1.46 +}
    1.47 +
    1.48 +bool
    1.49 +txLiteralExpr::isSensitiveTo(ContextSensitivity aContext)
    1.50 +{
    1.51 +    return false;
    1.52 +}
    1.53 +
    1.54 +#ifdef TX_TO_STRING
    1.55 +void
    1.56 +txLiteralExpr::toString(nsAString& aStr)
    1.57 +{
    1.58 +    switch (mValue->getResultType()) {
    1.59 +        case txAExprResult::NODESET:
    1.60 +        {
    1.61 +            aStr.AppendLiteral(" { Nodeset literal } ");
    1.62 +            return;
    1.63 +        }
    1.64 +        case txAExprResult::BOOLEAN:
    1.65 +        {
    1.66 +            if (mValue->booleanValue()) {
    1.67 +              aStr.AppendLiteral("true()");
    1.68 +            }
    1.69 +            else {
    1.70 +              aStr.AppendLiteral("false()");
    1.71 +            }
    1.72 +            return;
    1.73 +        }
    1.74 +        case txAExprResult::NUMBER:
    1.75 +        {
    1.76 +            txDouble::toString(mValue->numberValue(), aStr);
    1.77 +            return;
    1.78 +        }
    1.79 +        case txAExprResult::STRING:
    1.80 +        {
    1.81 +            StringResult* strRes =
    1.82 +                static_cast<StringResult*>(static_cast<txAExprResult*>
    1.83 +                                       (mValue));
    1.84 +            char16_t ch = '\'';
    1.85 +            if (strRes->mValue.FindChar(ch) != kNotFound) {
    1.86 +                ch = '\"';
    1.87 +            }
    1.88 +            aStr.Append(ch);
    1.89 +            aStr.Append(strRes->mValue);
    1.90 +            aStr.Append(ch);
    1.91 +            return;
    1.92 +        }
    1.93 +        case txAExprResult::RESULT_TREE_FRAGMENT:
    1.94 +        {
    1.95 +            aStr.AppendLiteral(" { RTF literal } ");
    1.96 +            return;
    1.97 +        }
    1.98 +    }
    1.99 +}
   1.100 +#endif

mercurial