From 736de8beb95c64cc59303589591b77f73af81d66 Mon Sep 17 00:00:00 2001 From: Ferdinand Majerech Date: Tue, 29 Jul 2014 23:22:16 +0200 Subject: [PATCH] Reader now uses validation to get the number of characters in the UTF8 buffer. --- source/dyaml/reader.d | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/dyaml/reader.d b/source/dyaml/reader.d index e90ce4c..768eb06 100644 --- a/source/dyaml/reader.d +++ b/source/dyaml/reader.d @@ -63,6 +63,8 @@ final class Reader // Index of the current character in the buffer. size_t charIndex_ = 0; + // Number of characters (code points) in buffer8_. + size_t characterCount_ = 0; // Current line in file. uint line_; @@ -133,6 +135,7 @@ final class Reader enforce(validateResult.valid, new ReaderException(validateResult.msg ~ validateResult.sequence.to!string)); + characterCount_ = validateResult.characterCount; this.sliceBuilder8 = SliceBuilder8(this); } @@ -148,7 +151,7 @@ final class Reader // Throws: ReaderException if trying to read past the end of the buffer. dchar peek(size_t index = 0) @safe pure nothrow @nogc { - if(buffer_.length <= charIndex_ + index) + if(characterCount_ <= charIndex_ + index) { // XXX This is risky; revert this and the 'risky' change in UTF decoder // if any bugs are introduced. We rely on the assumption that Reader