diff --git a/src/tools/collections.rs b/src/tools/collections.rs index 07aeb28..677d260 100644 --- a/src/tools/collections.rs +++ b/src/tools/collections.rs @@ -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 { + 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; impl Tool for Count { diff --git a/src/tools/mod.rs b/src/tools/mod.rs index 43e8d06..8f79013 100644 --- a/src/tools/mod.rs +++ b/src/tools/mod.rs @@ -50,13 +50,14 @@ pub mod time; /// Master list of all tools. /// /// 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::CreateTable, &collections::Insert, &collections::Rows, &collections::Select, &collections::String, + &collections::Replace, &collections::Transform, &collections::Where, &command::Bash,