The OpenD Programming Language

Buffer

Undocumented in source.
struct Buffer (
T
) {}

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Postblit

A postblit is present on this object, but not explicitly documented in the source.

Members

Functions

put
auto put(U[] data)

store data. Data copied

Examples

static assert(isInputRange!(Buffer!ubyte));
static assert(isForwardRange!(Buffer!ubyte));
static assert(hasLength!(Buffer!ubyte));
static assert(hasSlicing!(Buffer!ubyte));
static assert(isBidirectionalRange!(Buffer!ubyte));
static assert(isRandomAccessRange!(Buffer!ubyte));

auto b = Buffer!ubyte();
b.put("abc".representation.dup);
b.put("def".representation.dup);
assert(b.length == 6);
assert(b.toString == "abcdef");
assert(b.front == 'a');
assert(b.back == 'f');
assert(equal(b[0..$], "abcdef"));
assert(equal(b[$-2..$], "ef"));
assert(b == "abcdef");
b.popFront;
b.popBack;
assert(b.front == 'b');
assert(b.back == 'e');
assert(b.length == 4);
assert(retro(b).front == 'e');
assert(countUntil(b, 'e') == 3);
assert(equal(splitter(b, 'c').array[1], ['d', 'e'])); // split "bcde" on 'c'
assert(equal(b, "bcde"));
b.popFront; b.popFront;
assert(b.front == 'd');
assert(b.front == b[0]);
assert(b.back == b[$-1]);

auto c = Buffer!ubyte();
c.put("Header0: value0\n".representation.dup);
c.put("Header1: value1\n".representation.dup);
c.put("Header2: value2\n\nbody".representation.dup);
auto c_length = c.length;
auto eoh = countUntil(c, "\n\n");
assert(eoh == 47);
// foreach(header; c[0..eoh].splitter('\n') ) {
//     writeln(cast(string)header.data);
// }
assert(equal(findSplit(c, "\n\n")[2], "body"));
assert(c.length == c_length);
assert(c.indexOf('\n', 0) == 15);
assert(c.indexOf('\n', 16) == 31);
assert(c.indexOf('X', 16) == -1);

Meta