1
0

Implement replace

This commit is contained in:
Jeff 2023-08-25 10:42:19 -04:00
parent da532b79f3
commit 3d7b24299a
2 changed files with 29 additions and 1 deletions

View File

@ -73,6 +73,33 @@ impl Tool for String {
} }
} }
pub struct Replace;
impl Tool for Replace {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "replace",
description: "Replace all occurences of a substring in a string.",
group: "collections",
inputs: vec![ValueType::ListExact(vec![
ValueType::String,
ValueType::String,
ValueType::String,
])],
}
}
fn run(&self, argument: &Value) -> Result<Value> {
let argument = self.check_type(argument)?.as_list()?;
let target = argument[0].as_string()?;
let to_remove = argument[1].as_string()?;
let replacement = argument[2].as_string()?;
let result = target.replace(to_remove, replacement);
Ok(Value::String(result))
}
}
pub struct Count; pub struct Count;
impl Tool for Count { impl Tool for Count {

View File

@ -50,13 +50,14 @@ pub mod time;
/// Master list of all tools. /// Master list of all tools.
/// ///
/// This list is used to match identifiers with tools and to provide info to the shell. /// This list is used to match identifiers with tools and to provide info to the shell.
pub const TOOL_LIST: [&'static dyn Tool; 49] = [ pub const TOOL_LIST: [&'static dyn Tool; 50] = [
&collections::Count, &collections::Count,
&collections::CreateTable, &collections::CreateTable,
&collections::Insert, &collections::Insert,
&collections::Rows, &collections::Rows,
&collections::Select, &collections::Select,
&collections::String, &collections::String,
&collections::Replace,
&collections::Transform, &collections::Transform,
&collections::Where, &collections::Where,
&command::Bash, &command::Bash,