Lower- and uppercase string conversion functions
This commit is contained in:
parent
e4e79990da
commit
ff25573224
@ -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);
|
||||
|
@ -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())
|
||||
}
|
||||
|
8
tests/typ/utility/strings.typ
Normal file
8
tests/typ/utility/strings.typ
Normal 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("Ελλάδα"), "ΕΛΛΆΔΑ")
|
Loading…
Reference in New Issue
Block a user