From 46255846e6079a95cea81a1e7b19f7fe7d396806 Mon Sep 17 00:00:00 2001 From: Ferdinand Majerech Date: Fri, 25 Jul 2014 16:53:40 +0200 Subject: [PATCH] Using printNoGC to simplify @nogc error message building. --- source/dyaml/scanner.d | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/source/dyaml/scanner.d b/source/dyaml/scanner.d index 3fa3cb2..a84c1e6 100644 --- a/source/dyaml/scanner.d +++ b/source/dyaml/scanner.d @@ -27,6 +27,7 @@ import std.utf; import dyaml.fastcharsearch; import dyaml.escapes; import dyaml.exception; +import dyaml.nogcutil; import dyaml.queue; import dyaml.reader; import dyaml.style; @@ -1405,7 +1406,6 @@ final class Scanner dchar[] hex = reader_.get(hexLength); bool overflow; - import dyaml.nogcutil; const decoded = cast(dchar)parseNoGC!int(hex, 16u, overflow); if(overflow) { @@ -1423,23 +1423,10 @@ final class Scanner } else { - // Build an error message about the unsupported escape character - // without breaking purity or allocating. - const msg = "found unsupported escape character: "; - auto msgChars = msg.length; - msgBuffer_[0 .. msgChars] = msg; - if(c > char.max) - { - const unknown = ""; - msgBuffer_[msgChars .. msgChars + unknown.length] = unknown; - msgChars += unknown.length; - } - else - { - msgBuffer_[msgChars++] = cast(char)c; - } + auto msg = msgBuffer_.printNoGC("found unsupported escape " + "character", c); setError("While scanning a double quoted scalar", startMark, - cast(string)msgBuffer_[0 .. msgChars], reader_.mark); + cast(string)msg, reader_.mark); return; } }