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

import std.algorithm.comparison : equal;

assert(equal(encodeText(`foo & bar`), `foo &amp; bar`));
assert(equal(encodeText(`foo < bar`), `foo &lt; bar`));
assert(equal(encodeText(`foo > bar`), `foo > bar`));
assert(equal(encodeText(`foo ' bar`), `foo ' bar`));
assert(equal(encodeText(`foo " bar`), `foo " bar`));
assert(equal(encodeText("foo ]]> bar"), "foo ]]&gt; bar"));

assert(equal(encodeText("hello world"), "hello world"));

See Also

Meta