use crate::errors::ExecutorError;
use crate::evaluator::functions::coercion::coerce_to_string;
pub(in crate::evaluator::functions) fn replace(
args: &[vibesql_types::SqlValue],
) -> Result<vibesql_types::SqlValue, ExecutorError> {
if args.len() != 3 {
return Err(ExecutorError::UnsupportedFeature(format!(
"REPLACE requires exactly 3 arguments, got {}",
args.len()
)));
}
let text = match coerce_to_string(&args[0]) {
Some(s) => s,
None => return Ok(vibesql_types::SqlValue::Null),
};
let from = match coerce_to_string(&args[1]) {
Some(s) => s,
None => return Ok(vibesql_types::SqlValue::Null),
};
let to = match coerce_to_string(&args[2]) {
Some(s) => s,
None => return Ok(vibesql_types::SqlValue::Null),
};
Ok(vibesql_types::SqlValue::Varchar(arcstr::ArcStr::from(text.replace(&from, &to))))
}
pub(in crate::evaluator::functions) fn reverse(
args: &[vibesql_types::SqlValue],
) -> Result<vibesql_types::SqlValue, ExecutorError> {
if args.len() != 1 {
return Err(ExecutorError::UnsupportedFeature(format!(
"REVERSE requires exactly 1 argument, got {}",
args.len()
)));
}
match coerce_to_string(&args[0]) {
None => Ok(vibesql_types::SqlValue::Null),
Some(s) => {
let reversed: String = s.chars().rev().collect();
Ok(vibesql_types::SqlValue::Varchar(arcstr::ArcStr::from(reversed)))
}
}
}