aboutsummaryrefslogtreecommitdiff
path: root/man/man3/tomo-Text.translate.3
blob: 83fcf74bb579fc8199656a2644270783a8872d7b (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
'\" t
.\" Copyright (c) 2025 Bruce Hill
.\" All rights reserved.
.\"
.TH Text.translate 3 2025-04-21T14:44:34.265097 "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 lb
l l l l.
Name	Type	Description	Default
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
>> "A <tag> & an amperand".translate({
    "&" = "&amp;",
    "<" = "&lt;",
    ">" = "&gt;",
    '"" = "&quot",
    "'" = "&#39;",
})
= "A &lt;tag&gt; &amp; an ampersand"
.EE