diff --git a/std/xml.d b/std/xml.d index 1143dfa6d20..770c56fdbfb 100644 --- a/std/xml.d +++ b/std/xml.d @@ -564,7 +564,7 @@ class Document : Element this(xml.tag); prolog = s[0 .. tagString.ptr - s.ptr]; parse(xml); - epilog = xml.s; + epilog = *xml.s; } /** @@ -1721,12 +1721,20 @@ class DocumentParser : ElementParser body { xmlText = xmlText_; - s = xmlText; + s = &xmlText; super(); // Initialize everything parse(); // Parse through the root tag (but not beyond) } } +@system unittest +{ + auto doc = new Document(""); + assert(doc.elements.length == 1); + assert(doc.elements[0].tag.name == "child"); + assert(doc.items == doc.elements); +} + /** * Class for parsing an XML element. * @@ -1748,7 +1756,7 @@ class ElementParser { Tag tag_; string elementStart; - string s; + string* s; Handler commentHandler = null; Handler cdataHandler = null; @@ -1766,7 +1774,7 @@ class ElementParser } // Private constructor for empty tags - this(Tag tag, string t) @safe @nogc pure nothrow + this(Tag tag, string* t) @safe @nogc pure nothrow { s = t; this(); @@ -1849,7 +1857,7 @@ class ElementParser protected this() @safe @nogc pure nothrow { - elementStart = s; + elementStart = *s; } /** @@ -2005,37 +2013,37 @@ class ElementParser while (s.length != 0) { - if (startsWith(s,"")); + chop(*s,4); + t = chop(*s,indexOf(*s,"-->")); if (commentHandler.funcptr !is null) commentHandler(t); - chop(s,3); + chop(*s,3); } - else if (startsWith(s,"")); + chop(*s,9); + t = chop(*s,indexOf(*s,"]]>")); if (cdataHandler.funcptr !is null) cdataHandler(t); - chop(s,3); + chop(*s,3); } - else if (startsWith(s,"")); + chop(*s,2); + t = chop(*s,indexOf(*s,">")); if (xiHandler.funcptr !is null) xiHandler(t); - chop(s,1); + chop(*s,1); } - else if (startsWith(s,"")); + chop(*s,2); + t = chop(*s,indexOf(*s,"?>")); if (piHandler.funcptr !is null) piHandler(t); - chop(s,2); + chop(*s,2); } - else if (startsWith(s,"<")) + else if (startsWith(*s,"<")) { - tag_ = new Tag(s,true); + tag_ = new Tag(*s,true); if (root is null) return; // Return to constructor of derived class @@ -2091,7 +2099,7 @@ class ElementParser // Handle the pretend start tag string s2; - auto parser = new ElementParser(startTag,s2); + auto parser = new ElementParser(startTag,&s2); auto handler1 = startTag.name in onStartTag; if (handler1 !is null) (*handler1)(parser); else @@ -2113,7 +2121,7 @@ class ElementParser } else { - t = chop(s,indexOf(s,"<")); + t = chop(*s,indexOf(*s,"<")); if (rawTextHandler.funcptr !is null) rawTextHandler(t); else if (textHandler.funcptr !is null)