From acc7617fab546d176c8c33a75036027793edc9b5 Mon Sep 17 00:00:00 2001 From: Ferdinand Majerech Date: Sat, 26 Jul 2014 03:06:51 +0200 Subject: [PATCH] Forgotten SliceBuilder methods that enable new Scanner code. --- source/dyaml/reader.d | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/source/dyaml/reader.d b/source/dyaml/reader.d index 397ddcc..e4d0b7e 100644 --- a/source/dyaml/reader.d +++ b/source/dyaml/reader.d @@ -369,6 +369,29 @@ public: reader_.buffer_[end_++] = c; } + /// Insert a character into the slice, backwards characters before the end. + /// + /// Enlarges the slice by 1 char. Note that the slice can only extend up to the + /// current position in the Reader buffer. + void insertBack(dchar c, size_t backwards) @system pure nothrow @nogc + { + assert(inProgress, "insertBack called without begin"); + assert(end_ - backwards >= start_, "Trying to insert in front of the slice"); + + const point = end_ - backwards; + core.stdc.string.memmove(reader_.buffer_.ptr + point + 1, + reader_.buffer_.ptr + point, + backwards * dchar.sizeof); + ++end_; + reader_.buffer_[point] = c; + } + + /// Get the current length of the slice. + size_t length() @safe pure nothrow const @nogc + { + return end_ - start_; + } + /// A slice building transaction. /// /// Can be used to save and revert back to slice state.