update site

This commit is contained in:
mark
2023-05-04 05:42:45 +02:00
parent f8e23d0ce8
commit 5a8edd9605
6 changed files with 211 additions and 42 deletions

View File

@@ -84,6 +84,7 @@ pub enum BuiltinFunction {
IndexOf,
Trim,
Substring,
Replace,
Regex,
}
@@ -144,6 +145,7 @@ impl BuiltinFunction {
"index_of" => Self::IndexOf,
"trim" => Self::Trim,
"substring" => Self::Substring,
"replace" => Self::Replace,
"regex" => Self::Regex,
_ => return None,
})
@@ -484,6 +486,12 @@ impl BuiltinFunction {
.is_empty()
})
}
Self::Replace => {
input.len() == 3
&& input
.iter()
.all(|v| v.fits_in(&VSingleType::String.to(), info).is_empty())
}
Self::Trim => {
input.len() == 1 && input[0].fits_in(&VSingleType::String.to(), info).is_empty()
}
@@ -707,6 +715,7 @@ impl BuiltinFunction {
},
Self::Trim => VSingleType::String.into(),
Self::Substring => VSingleType::String.into(),
Self::Replace => VSingleType::String.to(),
Self::Regex => VType {
types: vec![
// [string ...]
@@ -1703,6 +1712,17 @@ impl BuiltinFunction {
unreachable!()
}
}
Self::Replace => {
if let (VDataEnum::String(a), VDataEnum::String(b), VDataEnum::String(c)) = (
args[0].run(vars, info).data,
args[1].run(vars, info).data,
args[2].run(vars, info).data,
) {
VDataEnum::String(a.replace(&b, &c)).to()
} else {
unreachable!()
}
}
Self::Regex => {
if args.len() == 2 {
if let (VDataEnum::String(a), VDataEnum::String(regex)) =