diff --git a/CHANGELOG.md b/CHANGELOG.md index a47556c..a67aa71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ All notable changes to eww will be listed here, starting at changes since versio - Add `notification` window type - Add drag and drop functionality to eventbox - Add `search`, `captures`, `stringlength`, `arraylength` and `objectlength` functions for expressions (By: MartinJM, ElKowar) +- Add `matches` function ### Notable Internal changes - Rework state management completely, now making local state and dynamic widget hierarchy changes possible. diff --git a/crates/simplexpr/src/eval.rs b/crates/simplexpr/src/eval.rs index 4952872..21c950b 100644 --- a/crates/simplexpr/src/eval.rs +++ b/crates/simplexpr/src/eval.rs @@ -270,6 +270,14 @@ fn call_expr_function(name: &str, args: Vec) -> Result Err(EvalError::WrongArgCount(name.to_string())), }, + "matches" => match args.as_slice() { + [string, pattern] => { + let string = string.as_string()?; + let pattern = regex::Regex::new(&pattern.as_string()?)?; + Ok(DynVal::from(pattern.is_match(&string))) + } + _ => Err(EvalError::WrongArgCount(name.to_string())), + }, "replace" => match args.as_slice() { [string, pattern, replacement] => { let string = string.as_string()?; diff --git a/docs/src/expression_language.md b/docs/src/expression_language.md index b29114a..848d445 100644 --- a/docs/src/expression_language.md +++ b/docs/src/expression_language.md @@ -33,7 +33,9 @@ Supported currently are the following features: - `round(number, decimal_digits)`: Round a number to the given amount of decimals - `replace(string, regex, replacement)`: Replace matches of a given regex in a string - `search(string, regex)`: Search for a given regex in a string (returns array) + - `matches(string, regex)`: check if a given string matches a given regex (returns bool) - `captures(string, regex)`: Get the captures of a given regex in a string (returns array) - - `hex_decode(string)`: Hex decodes the string - - `length(value)`: Gets the length of the value, as string length, json array length, or json object length + - `strlength(value)`: Gets the length of the string + - `arraylength(value)`: Gets the length of the array + - `objectlength(value)`: Gets the amount of entries in the object