Lower- and uppercase string conversion functions

This commit is contained in:
Laurenz 2021-08-30 16:39:16 +02:00
parent e4e79990da
commit ff25573224
3 changed files with 20 additions and 0 deletions

View File

@ -63,6 +63,8 @@ pub fn new() -> Scope {
std.def_func("rgb", rgb);
std.def_func("min", min);
std.def_func("max", max);
std.def_func("lower", lower);
std.def_func("upper", upper);
// Colors.
std.def_const("white", RgbaColor::WHITE);

View File

@ -75,3 +75,13 @@ fn minmax(args: &mut Arguments, goal: Ordering) -> TypResult<Value> {
}
Ok(extremum)
}
/// `lower`: Convert a string to lowercase.
pub fn lower(_: &mut EvalContext, args: &mut Arguments) -> TypResult<Value> {
Ok(args.expect::<Str>("string")?.to_lowercase().into())
}
/// `upper`: Convert a string to uppercase.
pub fn upper(_: &mut EvalContext, args: &mut Arguments) -> TypResult<Value> {
Ok(args.expect::<Str>("string")?.to_uppercase().into())
}

View File

@ -0,0 +1,8 @@
// Test string functions.
// Ref: false
---
#let memes = "ArE mEmEs gReAt?";
#test(lower(memes), "are memes great?")
#test(upper(memes), "ARE MEMES GREAT?")
#test(upper("Ελλάδα"), "ΕΛΛΆΔΑ")