txLiteralExpr.cpp 2.3 KB

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