From 44892df4c5686b292a058ca19eaba1e852fe42f3 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 6 Sep 2024 00:03:28 -0400 Subject: Add Text.trim() --- docs/text.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'docs') diff --git a/docs/text.md b/docs/text.md index 1d26040b..02c30912 100644 --- a/docs/text.md +++ b/docs/text.md @@ -279,6 +279,7 @@ Text.map(pattern:Pattern, fn:func(t:Text)->Text)->Text Text.replace(pattern:Pattern, replacement:Text, placeholder:Pattern=$//)->[Text] Text.replace_all(replacements:{Pattern:Text}, placeholder:Pattern=$//)->[Text] Text.split(pattern:Pattern)->[Text] +Text.trim(pattern=$/{whitespace}/, trim_left=yes, trim_right=yes)->[Text] ``` See [Text Functions](#Text-Functions) for the full API documentation. @@ -1098,6 +1099,41 @@ The text in title case. --- +## `trim` + +**Description:** +Trims the matching pattern from the left and/or right side of the text +See [Patterns](#patterns) for more information about patterns. + +**Usage:** +```tomo +trim(text: Text, pattern: Pattern = $/{whitespace/, trim_left: Bool = yes, trim_right: Bool = yes) -> Text +``` + +**Parameters:** + +- `text`: The text to be trimmed. +- `pattern`: The pattern that will be trimmed away. +- `trim_left`: Whether or not to trim from the front of the text. +- `trim_right`: Whether or not to trim from the back of the text. + +**Returns:** +The text without the trim pattern at either end. + +**Example:** +```tomo +>> " x y z $(\n)":trim() += "x y z" + +>> "abc123def":trim($/{!digit}/) += "123" + +>> " xyz ":trim(trim_right=no) += "xyz " +``` + +--- + ## `upper` **Description:** -- cgit v1.2.3