The state of string interpolation...one year later
ag0aep6g
anonymous at example.com
Mon Mar 18 16:24:46 UTC 2019
On 18.03.19 00:21, kinke wrote:
> As long as the embedded expressions are always separated by a string
> literal in the resulting tuple, incl. an empty one (`i"$(a)$(b)"` =>
> `"", a, "", b`), these embedded expressions can be identified (and
> appropriately transformed etc.) by an odd index.
I see. Like this:
void writelnToHTML(S ...)(S stuff)
{
static foreach (i, thing; stuff)
{
if (i % 2 == 0) write(thing);
else write(thing.toHTML);
}
writeln;
}
writelnToHTML(i`<html><body>
<title>$(title)</title>
<name>$(name)</name><age>$(age)</age>
<a href="$(link)">$(linkName)</a>
</body></html>
`);
That's pretty good. It's not quite foolproof; one might put arguments
before/after the interpolating, messing up the arrangement. But other
than that it seems nice.
More information about the Digitalmars-d
mailing list