Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(simplexpr): add uppercase and lowercase functions #1289

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ All notable changes to eww will be listed here, starting at changes since versio
- Add `log` function calls to simplexpr (By: topongo)
- Add `:lines` and `:wrap-mode` properties to label widget (By: vaporii)
- Add `value-pos` to scale widget (By: ipsvn)
- Add `uppercase` and `lowercase` functions for expressions (By: dod-101)

## [0.6.0] (21.04.2024)

Expand Down
14 changes: 14 additions & 0 deletions crates/simplexpr/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,20 @@ fn call_expr_function(name: &str, args: Vec<DynVal>) -> Result<DynVal, EvalError
}
_ => Err(EvalError::WrongArgCount(name.to_string())),
},
"uppercase" => match args.as_slice() {
[string] => {
let string = string.as_string()?;
Ok(DynVal::from(string.to_uppercase()))
}
_ => Err(EvalError::WrongArgCount(name.to_string())),
},
"lowercase" => match args.as_slice() {
[string] => {
let string = string.as_string()?;
Ok(DynVal::from(string.to_lowercase()))
}
_ => Err(EvalError::WrongArgCount(name.to_string())),
},

_ => Err(EvalError::UnknownFunction(name.to_string())),
}
Expand Down
1 change: 1 addition & 0 deletions docs/src/expression_language.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ Supported currently are the following features:
Same as other `formattime`, but does not accept timezone. Instead, it uses system's local timezone.
Check [chrono's documentation](https://docs.rs/chrono/latest/chrono/format/strftime/index.html) for more
information about format string.
- `uppercase(string)`, `lowercase(string)`: Convert a string to uppercase or lowercase