tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

txLiteralExpr.cpp (2138B)


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