Implement replace
This commit is contained in:
parent
da532b79f3
commit
3d7b24299a
@ -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;
|
||||
|
||||
impl Tool for Count {
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user