Add matches function to simplexpr
This commit is contained in:
parent
0f9847c518
commit
776dc787e7
3 changed files with 13 additions and 2 deletions
|
@ -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.
|
||||
|
|
|
@ -270,6 +270,14 @@ fn call_expr_function(name: &str, args: Vec<DynVal>) -> Result<DynVal, EvalError
|
|||
}
|
||||
_ => 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()?;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue