XMLWriter.writeIndent

Writes a newline followed by an indent to the output range.

In general, the various write functions already provide this functionality via their Newline parameter, but there may be cases where it is desirable to insert a newline independently of calling a write function.

If arbitrary whitespace needs to be inserted, then output can be used to get at the output range so that it can be written to directly.

struct XMLWriter(OR)
void
writeIndent
()
if (
isOutputRange!(OR, char)
)

Examples

import std.array : appender;

auto writer = xmlWriter(appender!string());
writer.writeStartTag("root", Newline.no);
assert(writer.output.data == "<root>");

writer.writeIndent();
assert(writer.output.data ==
       "<root>\n" ~
       "    ");

writer.writeStartTag("foo");
assert(writer.output.data ==
       "<root>\n" ~
       "    \n" ~
       "    <foo>");

writer.writeIndent();
assert(writer.output.data ==
       "<root>\n" ~
       "    \n" ~
       "    <foo>\n" ~
       "        ");

writer.writeText("some text");
assert(writer.output.data ==
       "<root>\n" ~
       "    \n" ~
       "    <foo>\n" ~
       "        \n" ~
       "        some text");

writer.writeIndent();
assert(writer.output.data ==
       "<root>\n" ~
       "    \n" ~
       "    <foo>\n" ~
       "        \n" ~
       "        some text\n" ~
       "        ");

writer.writeEndTag();
writer.writeEndTag();
assert(writer.output.data ==
       "<root>\n" ~
       "    \n" ~
       "    <foo>\n" ~
       "        \n" ~
       "        some text\n" ~
       "        \n" ~
       "    </foo>\n" ~
       "</root>");

Meta