use super::*;
mod mutation;
pub(super) use mutation::{eval_pad, eval_replace, eval_split};
pub(super) fn eval_unary_string_op<F>(
args: &[Expr],
injected: Option<&EvalValue>,
record: &JsonValue,
context: Option<&JsonValue>,
out: &JsonValue,
base_path: &str,
locals: Option<&EvalLocals<'_>>,
op: F,
) -> Result<EvalValue, TransformError>
where
F: FnOnce(&JsonValue, &str) -> Result<JsonValue, TransformError>,
{
let total_len = args_len(args, injected);
if total_len != 1 {
return Err(TransformError::new(
TransformErrorKind::ExprError,
"expr.args must contain exactly one item",
)
.with_path(format!("{}.args", base_path)));
}
let arg_path = format!("{}.args[0]", base_path);
let value = eval_expr_at_index(0, args, injected, record, context, out, base_path, locals)?;
match value {
EvalValue::Missing => Ok(EvalValue::Missing),
EvalValue::Value(value) => {
if value.is_null() {
return Err(TransformError::new(
TransformErrorKind::ExprError,
"expr arg must not be null",
)
.with_path(arg_path));
}
op(&value, &arg_path).map(EvalValue::Value)
}
}
}