use crate::lang::adapter::Adapter;
use crate::lang::args::arg_into_string;
use crate::lang::args::eval_unary_arg;
use crate::lang::arity::Arity;
use crate::lang::arity::assert_func_arity;
use crate::lang::error::Error;
use crate::lang::machine::Machine;
use crate::lang::node::Node;
use crate::value::Value;
pub(crate) fn percent_decode(
adapter: &impl Adapter,
machine: &mut Machine<'_>,
stdin: Option<&Value>,
node: Node,
) -> Result<Value, Error> {
assert_func_arity(adapter, machine, stdin, &node, &Arity::new(1))?;
let value = eval_unary_arg(adapter, machine, stdin, node)?;
let value = arg_into_string(value).unwrap_or_default();
let value = percent_encoding::percent_decode_str(&value)
.decode_utf8_lossy()
.into_owned();
Ok(Value::from(value))
}