(355 lines)
1 '\" t2 .\" Copyright (c) 2026 Bruce Hill3 .\" All rights reserved.4 .\"5 .TH Text 3 2026-03-14 "Tomo man-pages"6 .SH NAME7 Text \- a Tomo type8 .SH LIBRARY9 Tomo Standard Library10 .fi11 .SH METHODS13 .TP14 .BI Text.as_c_string\ :\ func(text:\ Text\ ->\ CString)15 Converts a \fBText\fR value to a C-style string.17 For more, see:18 .BR Tomo-Text.as_c_string (3)21 .TP22 .BI Text.at\ :\ func(text:\ Text,\ index:\ Int\ ->\ Text)23 Get the graphical cluster at a given index. This is similar to \fBstr[i]\fR with ASCII text, but has more correct behavior for unicode text.25 For more, see:26 .BR Tomo-Text.at (3)29 .TP30 .BI Text.by_line\ :\ func(text:\ Text\ ->\ func(->Text?))31 Returns an iterator function that can be used to iterate over the lines in a text.33 For more, see:34 .BR Tomo-Text.by_line (3)37 .TP38 .BI Text.by_split\ :\ func(text:\ Text,\ delimiter:\ Text\ =\ ""\ ->\ func(->Text?))39 Returns an iterator function that can be used to iterate over text separated by a delimiter.41 For more, see:42 .BR Tomo-Text.by_split (3)45 .TP46 .BI Text.by_split_any\ :\ func(text:\ Text,\ delimiters:\ Text\ =\ "\ $\[rs]t\[rs]r\[rs]n"\ ->\ func(->Text?))47 Returns an iterator function that can be used to iterate over text separated by one or more characters (grapheme clusters) from a given text of delimiters.49 For more, see:50 .BR Tomo-Text.by_split_any (3)53 .TP54 .BI Text.caseless_equals\ :\ func(a:\ Text,\ b:\ Text,\ language:\ Text\ =\ "C"\ ->\ Bool)55 Checks whether two texts are equal, ignoring the casing of the letters (i.e. case-insensitive comparison).57 For more, see:58 .BR Tomo-Text.caseless_equals (3)61 .TP62 .BI Text.codepoint_names\ :\ func(text:\ Text\ ->\ [Text])63 Returns a list of the names of each codepoint in the text.65 For more, see:66 .BR Tomo-Text.codepoint_names (3)69 .TP70 .BI Text.distance\ :\ func(a:\ Text,\ b:\ Text,\ language:\ Text\ =\ "C"\ ->\ Num)71 Get an approximate distance between two texts, such that when the distance is small, the texts are similar and when the distance is large, the texts are dissimilar.73 For more, see:74 .BR Tomo-Text.distance (3)77 .TP78 .BI Text.ends_with\ :\ func(text:\ Text,\ suffix:\ Text,\ remainder:\ &Text?\ =\ none\ ->\ Bool)79 Checks if the \fBText\fR ends with a literal suffix text.81 For more, see:82 .BR Tomo-Text.ends_with (3)85 .TP86 .BI Text.find\ :\ func(text:\ Text,\ target:\ Text,\ start:\ Int\ =\ 1\ ->\ Int)87 Find a substring within a text and return its index, if found.89 For more, see:90 .BR Tomo-Text.find (3)93 .TP94 .BI Text.from\ :\ func(text:\ Text,\ first:\ Int\ ->\ Text)95 Get a slice of the text, starting at the given position.97 For more, see:98 .BR Tomo-Text.from (3)101 .TP102 .BI Text.from_c_string\ :\ func(str:\ CString\ ->\ Text)103 Converts a C-style string to a \fBText\fR value.105 For more, see:106 .BR Tomo-Text.from_c_string (3)109 .TP110 .BI Text.from_codepoint_names\ :\ func(codepoint_names:\ [Text]\ ->\ [Text])111 Returns text that has the given codepoint names (according to the Unicode specification) as its codepoints.113 For more, see:114 .BR Tomo-Text.from_codepoint_names (3)117 .TP118 .BI Text.from_utf16\ :\ func(bytes:\ [Int16]\ ->\ [Text])119 Returns text that has been constructed from the given UTF16 sequence.121 For more, see:122 .BR Tomo-Text.from_utf16 (3)125 .TP126 .BI Text.from_utf32\ :\ func(codepoints:\ [Int32]\ ->\ [Text])127 Returns text that has been constructed from the given UTF32 codepoints.129 For more, see:130 .BR Tomo-Text.from_utf32 (3)133 .TP134 .BI Text.from_utf8\ :\ func(bytes:\ [Byte]\ ->\ [Text])135 Returns text that has been constructed from the given UTF8 bytes.137 For more, see:138 .BR Tomo-Text.from_utf8 (3)141 .TP142 .BI Text.has\ :\ func(text:\ Text,\ target:\ Text\ ->\ Bool)143 Checks if the \fBText\fR contains some target text.145 For more, see:146 .BR Tomo-Text.has (3)149 .TP150 .BI Text.join\ :\ func(glue:\ Text,\ pieces:\ [Text]\ ->\ Text)151 Joins a list of text pieces with a specified glue.153 For more, see:154 .BR Tomo-Text.join (3)157 .TP158 .BI Text.left_pad\ :\ func(text:\ Text,\ width:\ Int,\ pad:\ Text\ =\ "\ ",\ language:\ Text\ =\ "C"\ ->\ Text)159 Pad some text on the left side so it reaches a target width.161 For more, see:162 .BR Tomo-Text.left_pad (3)165 .TP166 .BI Text.lines\ :\ func(text:\ Text\ ->\ [Text])167 Splits the text into a list of lines of text, preserving blank lines, ignoring trailing newlines, and handling \fB\r\n\fR the same as \fB\n\fR.169 For more, see:170 .BR Tomo-Text.lines (3)173 .TP174 .BI Text.lower\ :\ func(text:\ Text,\ language:\ Text\ =\ "C"\ ->\ Text)175 Converts all characters in the text to lowercase.177 For more, see:178 .BR Tomo-Text.lower (3)181 .TP182 .BI Text.matches_glob\ :\ func(path:\ Text,\ glob:\ Text\ ->\ Bool)183 Return whether or not the text matches the given glob.185 For more, see:186 .BR Tomo-Text.matches_glob (3)189 .TP190 .BI Text.middle_pad\ :\ func(text:\ Text,\ width:\ Int,\ pad:\ Text\ =\ "\ ",\ language:\ Text\ =\ "C"\ ->\ Text)191 Pad some text on the left and right side so it reaches a target width.193 For more, see:194 .BR Tomo-Text.middle_pad (3)197 .TP198 .BI Text.quoted\ :\ func(text:\ Text,\ color:\ Bool\ =\ no,\ quotation_mark:\ Text\ =\ `"`\ ->\ Text)199 Formats the text with quotation marks and escapes.201 For more, see:202 .BR Tomo-Text.quoted (3)205 .TP206 .BI Text.repeat\ :\ func(text:\ Text,\ count:\ Int\ ->\ Text)207 Repeat some text multiple times.209 For more, see:210 .BR Tomo-Text.repeat (3)213 .TP214 .BI Text.replace\ :\ func(text:\ Text,\ target:\ Text,\ replacement:\ Text\ ->\ Text)215 Replaces occurrences of a target text with a replacement text.217 For more, see:218 .BR Tomo-Text.replace (3)221 .TP222 .BI Text.reversed\ :\ func(text:\ Text\ ->\ Text)223 Return a text that has the grapheme clusters in reverse order.225 For more, see:226 .BR Tomo-Text.reversed (3)229 .TP230 .BI Text.right_pad\ :\ func(text:\ Text,\ width:\ Int,\ pad:\ Text\ =\ "\ ",\ language:\ Text\ =\ "C"\ ->\ Text)231 Pad some text on the right side so it reaches a target width.233 For more, see:234 .BR Tomo-Text.right_pad (3)237 .TP238 .BI Text.slice\ :\ func(text:\ Text,\ from:\ Int\ =\ 1,\ to:\ Int\ =\ -1\ ->\ Text)239 Get a slice of the text.241 For more, see:242 .BR Tomo-Text.slice (3)245 .TP246 .BI Text.split\ :\ func(text:\ Text,\ delimiter:\ Text\ =\ ""\ ->\ [Text])247 Splits the text into a list of substrings based on exact matches of a delimiter.249 For more, see:250 .BR Tomo-Text.split (3)253 .TP254 .BI Text.split_any\ :\ func(text:\ Text,\ delimiters:\ Text\ =\ "\ $\[rs]t\[rs]r\[rs]n"\ ->\ [Text])255 Splits the text into a list of substrings at one or more occurrences of a set of delimiter characters (grapheme clusters).257 For more, see:258 .BR Tomo-Text.split_any (3)261 .TP262 .BI Text.starts_with\ :\ func(text:\ Text,\ prefix:\ Text,\ remainder:\ &Text?\ =\ none\ ->\ Bool)263 Checks if the \fBText\fR starts with a literal prefix text.265 For more, see:266 .BR Tomo-Text.starts_with (3)269 .TP270 .BI Text.title\ :\ func(text:\ Text,\ language:\ Text\ =\ "C"\ ->\ Text)271 Converts the text to title case (capitalizing the first letter of each word).273 For more, see:274 .BR Tomo-Text.title (3)277 .TP278 .BI Text.to\ :\ func(text:\ Text,\ last:\ Int\ ->\ Text)279 Get a slice of the text, ending at the given position.281 For more, see:282 .BR Tomo-Text.to (3)285 .TP286 .BI Text.translate\ :\ func(text:\ Text,\ translations:\ {Text:Text}\ ->\ Text)287 Takes a table mapping target texts to their replacements and performs all the replacements in the table on the whole text. At each position, the first matching replacement is applied and the matching moves on to *after* the replacement text, so replacement text is not recursively modified. See Text.replace() for more information about replacement behavior.289 For more, see:290 .BR Tomo-Text.translate (3)293 .TP294 .BI Text.trim\ :\ func(text:\ Text,\ to_trim:\ Text\ =\ "\ $\[rs]t\[rs]r\[rs]n",\ left:\ Bool\ =\ yes,\ right:\ Bool\ =\ yes\ ->\ Text)295 Trims the given characters (grapheme clusters) from the left and/or right side of the text.297 For more, see:298 .BR Tomo-Text.trim (3)301 .TP302 .BI Text.upper\ :\ func(text:\ Text,\ language:\ Text\ =\ "C"\ ->\ Text)303 Converts all characters in the text to uppercase.305 For more, see:306 .BR Tomo-Text.upper (3)309 .TP310 .BI Text.utf16\ :\ func(text:\ Text\ ->\ [Int16])311 Returns a list of Unicode code points for UTF16 encoding of the text.313 For more, see:314 .BR Tomo-Text.utf16 (3)317 .TP318 .BI Text.utf32\ :\ func(text:\ Text\ ->\ [Int32])319 Returns a list of Unicode code points for UTF32 encoding of the text.321 For more, see:322 .BR Tomo-Text.utf32 (3)325 .TP326 .BI Text.utf8\ :\ func(text:\ Text\ ->\ [Byte])327 Converts a \fBText\fR value to a list of bytes representing a UTF8 encoding of the text.329 For more, see:330 .BR Tomo-Text.utf8 (3)333 .TP334 .BI Text.width\ :\ func(text:\ Text\ ->\ Int)335 Returns the display width of the text as seen in a terminal with appropriate font rendering. This is usually the same as the text's \fB.length\fR, but there are some characters like emojis that render wider than 1 cell.337 For more, see:338 .BR Tomo-Text.width (3)341 .TP342 .BI Text.without_prefix\ :\ func(text:\ Text,\ prefix:\ Text\ ->\ Text)343 Returns the text with a given prefix removed (if present).345 For more, see:346 .BR Tomo-Text.without_prefix (3)349 .TP350 .BI Text.without_suffix\ :\ func(text:\ Text,\ suffix:\ Text\ ->\ Text)351 Returns the text with a given suffix removed (if present).353 For more, see:354 .BR Tomo-Text.without_suffix (3)