diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-05-03 16:59:13 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-05-04 00:14:31 +0200 |
| commit | 507c5fc92563560426db0d86c0348880b0493467 (patch) | |
| tree | 45116b62fb0fffe8e88d6c96ae1fcf11c73f8ee9 /src/library/utility/string.rs | |
| parent | e18a896a93cae987aa30addd40e678bf0064fd31 (diff) | |
Text replacement show rules
Diffstat (limited to 'src/library/utility/string.rs')
| -rw-r--r-- | src/library/utility/string.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/library/utility/string.rs b/src/library/utility/string.rs index 92d80be2..0b309b31 100644 --- a/src/library/utility/string.rs +++ b/src/library/utility/string.rs @@ -1,3 +1,6 @@ +use lipsum::lipsum_from_seed; + +use crate::eval::Regex; use crate::library::prelude::*; use crate::library::text::{Case, TextNode}; @@ -37,6 +40,18 @@ fn case(case: Case, args: &mut Args) -> TypResult<Value> { }) } +/// Create blind text. +pub fn lorem(_: &mut Context, args: &mut Args) -> TypResult<Value> { + let words: usize = args.expect("number of words")?; + Ok(Value::Str(lipsum_from_seed(words, 97).into())) +} + +/// Create a regular expression. +pub fn regex(_: &mut Context, args: &mut Args) -> TypResult<Value> { + let Spanned { v, span } = args.expect::<Spanned<EcoString>>("regular expression")?; + Ok(Regex::new(&v).at(span)?.into()) +} + /// Converts an integer into one or multiple letters. pub fn letter(_: &mut Context, args: &mut Args) -> TypResult<Value> { convert(Numbering::Letter, args) |
