1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
This module provides support for formatting of large or complex strings beyond
the scope of [[fmt::]]. A template is compiled using [[compile]], then executed
with [[execute]] to print formatted text to an [[io::handle]].
The template format is a string with variables substituted using "$". Variable
names consist of alphanumeric ASCII characters (i.e. for which
[[ascii::isalnum]] returns true) or underscores ('_'). A literal "$" may be
printed by using it twice: "$$". Variables may also be used with braces, i.e.
${variable}, so that they can be placed immediately next to alphanumeric
characters; such variables may include non-alphanumeric characters other than
'{' and '}'.
const src = "Hello, $user! Your balance is $$$balance.\n";
const template = template::compile(src)!;
defer template::finish(&template);
template::execute(&template, os::stdout,
("user", "ddevault"),
("balance", 1000),
)!; // "Hello, ddevault! Your balance is $1000.
|