blob: 2cac6a4700423b7f4a48a5e801168d700a945d22 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
'\" t
.\" Copyright (c) 2025 Bruce Hill
.\" All rights reserved.
.\"
.TH Text.translate 3 2025-11-29 "Tomo man-pages"
.SH NAME
Text.translate \- perform multiple replacements
.SH LIBRARY
Tomo Standard Library
.SH SYNOPSIS
.nf
.BI Text.translate\ :\ func(text:\ Text,\ translations:\ {Text:Text}\ ->\ Text)
.fi
.SH DESCRIPTION
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.
.SH ARGUMENTS
.TS
allbox;
lb lb lbx
l l l.
Name Type Description
text Text The text to be translated.
translations {Text:Text} A table mapping from target text to its replacement.
.TE
.SH RETURN
The text with all occurrences of the targets replaced with their corresponding replacement text.
.SH EXAMPLES
.EX
text := "A <tag> & an amperand".translate({
"&": "&",
"<": "<",
">": ">",
'"": """,
"'": "'",
})
assert text == "A <tag> & an ampersand"
.EE
.SH SEE ALSO
.BR Tomo-Text (3)
|