encodeText

Returns a lazy range of code units which encodes any characters which cannot be put in an dxml.parser.EntityType._text in their literal form.

encodeText is intended primarily to be used with dxml.writer.XMLWriter.writeText to ensure that characters which cannot appear in their literal form do not appear in their literal form.

Specifically, what encodeText does is

convert & to &
convert < to &lt;
convert ]]> to ]]&gt;
encodeText
(
R
)
()
if (
isForwardRange!R &&
isSomeChar!(ElementType!R)
)

Examples

1 import std.algorithm.comparison : equal;
2 
3 assert(equal(encodeText(`foo & bar`), `foo &amp; bar`));
4 assert(equal(encodeText(`foo < bar`), `foo &lt; bar`));
5 assert(equal(encodeText(`foo > bar`), `foo > bar`));
6 assert(equal(encodeText(`foo ' bar`), `foo ' bar`));
7 assert(equal(encodeText(`foo " bar`), `foo " bar`));
8 assert(equal(encodeText("foo ]]> bar"), "foo ]]&gt; bar"));
9 
10 assert(equal(encodeText("hello world"), "hello world"));

See Also

Meta