Removed UTF-32 parts of Reader API.

This commit is contained in:
Ferdinand Majerech 2014-07-29 23:15:08 +02:00
parent d1aaec6a60
commit ffef7bf6fc

View file

@ -192,38 +192,26 @@ final class Reader
/// Note: This gets only a "view" into the internal buffer, /// Note: This gets only a "view" into the internal buffer,
/// which get invalidated after other Reader calls. /// which get invalidated after other Reader calls.
/// ///
/// Params: length = Number of characters to get. May reach past the end of the /// Params: length = Number of characters (code points, not bytes) to get. May
/// buffer; in that case the returned slice will be shorter. /// reach past the end of the buffer; in that case the
/// returned slice will be shorter.
/// ///
/// Returns: Characters starting at current position or an empty slice if out of bounds. /// Returns: Characters starting at current position or an empty slice if out of bounds.
dchar[] prefix(size_t length) @safe pure nothrow @nogc
{
return slice(0, length);
}
char[] prefix8(const size_t length) @safe pure nothrow @nogc char[] prefix8(const size_t length) @safe pure nothrow @nogc
{ {
return slice8(length); return slice8(length);
} }
/// Get a slice view of the internal buffer. /// Get a slice view of the internal buffer, starting at the current position.
/// ///
/// Note: This gets only a "view" into the internal buffer, /// Note: This gets only a "view" into the internal buffer,
/// which get invalidated after other Reader calls. /// which get invalidated after other Reader calls.
/// ///
/// Params: start = Start of the slice relative to current position. /// Params: end = End of the slice relative to current position. May reach past
/// end = End of the slice relative to current position. May reach /// the end of the buffer; in that case the returned slice will
/// past the end of the buffer; in that case the returned /// be shorter.
/// slice will be shorter.
/// ///
/// Returns: Slice into the internal buffer or an empty slice if out of bounds. /// Returns: Slice into the internal buffer or an empty slice if out of bounds.
dchar[] slice(size_t start, size_t end) @trusted pure nothrow @nogc
{
start += bufferOffset_;
end = min(buffer_.length, end + bufferOffset_);
assert(end >= start, "Trying to read a slice that starts after its end");
return buffer_[start .. end];
}
char[] slice8(const size_t end) @safe pure nothrow @nogc char[] slice8(const size_t end) @safe pure nothrow @nogc
{ {
// Fast path in case the caller has already peek()ed all the way to end. // Fast path in case the caller has already peek()ed all the way to end.
@ -260,15 +248,9 @@ final class Reader
/// Get specified number of characters, moving buffer position beyond them. /// Get specified number of characters, moving buffer position beyond them.
/// ///
/// Params: length = Number or characters to get. /// Params: length = Number or characters (code points, not bytes) to get.
/// ///
/// Returns: Characters starting at current position. /// Returns: Characters starting at current position.
dchar[] get(size_t length) @safe pure nothrow @nogc
{
auto result = prefix(length);
forward(length);
return result;
}
char[] get8(const size_t length) @safe pure nothrow @nogc char[] get8(const size_t length) @safe pure nothrow @nogc
{ {
auto result = prefix8(length); auto result = prefix8(length);
@ -650,7 +632,6 @@ auto decodeUTF(ubyte[] input, UTFEncoding encoding) @safe pure nothrow
struct Result struct Result
{ {
string errorMessage; string errorMessage;
dchar[] decoded; dchar[] decoded;
} }
@ -835,7 +816,7 @@ void testPeekPrefixForward(R)()
assert(reader.peek(2) == 't'); assert(reader.peek(2) == 't');
assert(reader.peek(3) == 'a'); assert(reader.peek(3) == 'a');
assert(reader.peek(4) == '\0'); assert(reader.peek(4) == '\0');
assert(reader.prefix(4) == "data"); assert(reader.prefix8(4) == "data");
// assert(reader.prefix(6) == "data\0"); // assert(reader.prefix(6) == "data\0");
reader.forward(2); reader.forward(2);
assert(reader.peek(1) == 'a'); assert(reader.peek(1) == 'a');