escape

Escapes characters in the input text.

escape
(
Range
)
(
Range range
,
const char[2][] pairs
)
if (
isInputRange!Range &&
isSomeChar!(ElementType!Range)
)
in { foreach (pair; pairs) { assert (pair[0] != '\\', "the backslash should not be set as pair"); assert (pair[1] != '\\', "the backslash should not be set as pair"); } }

Parameters

range
Type: Range

The character range to process. The source is not consumed.

pairs
Type: char[2][]

An array of pair. Each pair (char[2]) defines a source and a target character. The slash is automatically escaped and must not be included in the array.

Return Value

Type: auto

An array of character whose type matches the range element type.

Examples

1 assert(`1"`.escape([['"','"']]) == `1\"`);
2 assert(`1"1"11"1`.escape([['"','"']]) == `1\"1\"11\"1`);
3 assert("\n\"1".escape([['"','"'],['\n','n']]) == `\n\"1`);
4 assert(`1\"`.escape([['"','"']]) == `1\\"`);
5 assert(`\`.escape([]) == `\\`);

Meta