From 40fe7090d99d295b800111c0207409674e7598e7 Mon Sep 17 00:00:00 2001 From: Ferdinand Majerech Date: Tue, 29 Jul 2014 03:11:17 +0200 Subject: [PATCH] UTF-8 scanTagURI. --- source/dyaml/scanner.d | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/source/dyaml/scanner.d b/source/dyaml/scanner.d index 1459029..57a7a8a 100644 --- a/source/dyaml/scanner.d +++ b/source/dyaml/scanner.d @@ -1935,6 +1935,40 @@ final class Scanner enum contextMsg = "While parsing a " ~ name; error(contextMsg, startMark, expected("URI", c), reader_.mark); } + void scanTagURIToSlice8(string name)(const Mark startMark) + @trusted pure nothrow // @nogc + { + // Note: we do not check if URI is well-formed. + dchar c = reader_.peek(); + const startLen = reader_.sliceBuilder8.length; + { + uint length = 0; + while(c.isAlphaNum || "-;/?:@&=+$,_.!~*\'()[]%"d.canFind(c)) + { + if(c == '%') + { + auto chars = reader_.get8(length); + reader_.sliceBuilder8.write(chars); + length = 0; + scanURIEscapesToSlice8!name(startMark); + if(error_) { return; } + } + else { ++length; } + c = reader_.peek(length); + } + if(length > 0) + { + auto chars = reader_.get8(length); + reader_.sliceBuilder8.write(chars); + length = 0; + } + } + // OK if we scanned something, error otherwise. + if(reader_.sliceBuilder8.length > startLen) { return; } + + enum contextMsg = "While parsing a " ~ name; + error(contextMsg, startMark, expected("URI", c), reader_.mark); + } // Not @nogc yet because std.utf.decode is not @nogc /// Scan URI escape sequences.