2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "txExpr.h"
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
txLiteralExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mValue, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
*aResult = mValue;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Expr::ResultType resultTypes[] =
|
|
|
|
{
|
|
|
|
Expr::NODESET_RESULT, // NODESET
|
|
|
|
Expr::BOOLEAN_RESULT, // BOOLEAN
|
|
|
|
Expr::NUMBER_RESULT, // NUMBER
|
|
|
|
Expr::STRING_RESULT, // STRING
|
|
|
|
Expr::RTF_RESULT // RESULT_TREE_FRAGMENT
|
|
|
|
};
|
|
|
|
|
|
|
|
Expr::ResultType
|
|
|
|
txLiteralExpr::getReturnType()
|
|
|
|
{
|
|
|
|
return resultTypes[mValue->getResultType()];
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr*
|
2012-08-22 08:56:38 -07:00
|
|
|
txLiteralExpr::getSubExprAt(uint32_t aPos)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
txLiteralExpr::setSubExprAt(uint32_t aPos, Expr* aExpr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("setting bad subexpression index");
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
txLiteralExpr::isSensitiveTo(ContextSensitivity aContext)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TX_TO_STRING
|
|
|
|
void
|
|
|
|
txLiteralExpr::toString(nsAString& aStr)
|
|
|
|
{
|
|
|
|
switch (mValue->getResultType()) {
|
|
|
|
case txAExprResult::NODESET:
|
|
|
|
{
|
|
|
|
aStr.AppendLiteral(" { Nodeset literal } ");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case txAExprResult::BOOLEAN:
|
|
|
|
{
|
|
|
|
if (mValue->booleanValue()) {
|
|
|
|
aStr.AppendLiteral("true()");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aStr.AppendLiteral("false()");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case txAExprResult::NUMBER:
|
|
|
|
{
|
2011-11-20 03:18:26 -08:00
|
|
|
txDouble::toString(mValue->numberValue(), aStr);
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case txAExprResult::STRING:
|
|
|
|
{
|
|
|
|
StringResult* strRes =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<StringResult*>(static_cast<txAExprResult*>
|
|
|
|
(mValue));
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t ch = '\'';
|
2007-03-22 10:30:00 -07:00
|
|
|
if (strRes->mValue.FindChar(ch) != kNotFound) {
|
|
|
|
ch = '\"';
|
|
|
|
}
|
|
|
|
aStr.Append(ch);
|
|
|
|
aStr.Append(strRes->mValue);
|
|
|
|
aStr.Append(ch);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case txAExprResult::RESULT_TREE_FRAGMENT:
|
|
|
|
{
|
|
|
|
aStr.AppendLiteral(" { RTF literal } ");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|