use bumpalo::Bump;
use super::DataValue;
pub(crate) fn data_to_str<'a>(v: &DataValue<'a>, arena: &'a Bump) -> &'a str {
match v {
DataValue::String(s) => s,
DataValue::Null => "",
DataValue::Bool(true) => "true",
DataValue::Bool(false) => "false",
DataValue::Number(n) => arena.alloc_str(&n.to_string()),
other => arena.alloc_str(&other.to_string()),
}
}
#[inline(always)]
pub(crate) fn truthy_arena(v: &DataValue<'_>, engine: &crate::Engine) -> bool {
use crate::config::TruthyEvaluator;
match &engine.config().truthy_evaluator {
TruthyEvaluator::JavaScript | TruthyEvaluator::Python => super::truthy_js_arena(v),
TruthyEvaluator::StrictBoolean => match v {
DataValue::Null => false,
DataValue::Bool(b) => *b,
_ => true,
},
TruthyEvaluator::Custom(f) => f(&v.to_owned()),
}
}