diff options
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/typst/src/eval/methods.rs | 1 | ||||
| -rw-r--r-- | crates/typst/src/eval/str.rs | 5 |
2 files changed, 6 insertions, 0 deletions
diff --git a/crates/typst/src/eval/methods.rs b/crates/typst/src/eval/methods.rs index 6127a807..ed11d8a7 100644 --- a/crates/typst/src/eval/methods.rs +++ b/crates/typst/src/eval/methods.rs @@ -82,6 +82,7 @@ pub fn call( let count = args.named("count")?; string.replace(vm, pattern, with, count)?.into_value() } + "rev" => string.rev().into_value(), "trim" => { let pattern = args.eat()?; let at = args.named("at")?; diff --git a/crates/typst/src/eval/str.rs b/crates/typst/src/eval/str.rs index 30139f10..b21d2ff9 100644 --- a/crates/typst/src/eval/str.rs +++ b/crates/typst/src/eval/str.rs @@ -324,6 +324,11 @@ impl Str { Ok(Self(self.0.repeat(n))) } + /// Reverse the string. + pub fn rev(&self) -> Self { + self.as_str().graphemes(true).rev().collect::<String>().into() + } + /// Resolve an index or throw an out of bounds error. fn locate(&self, index: i64) -> StrResult<usize> { self.locate_opt(index)? |
