aboutsummaryrefslogtreecommitdiff
path: root/std/buffer.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-12-23 12:00:25 -0500
committerAndrew Kelley <superjoe30@gmail.com>2017-12-23 12:00:25 -0500
commitfe660462837231353b846bf398637ca84f67bfc9 (patch)
tree37336cfcf44810d73d111a57207b843a01fd205f /std/buffer.zig
parentfe39ca01bcbee0077b21d5ddc2776df974e8c6d3 (diff)
parent39c7bd24e4f768b23074b8634ac637b175b7639f (diff)
downloadzig-fe660462837231353b846bf398637ca84f67bfc9.tar.gz
zig-fe660462837231353b846bf398637ca84f67bfc9.zip
Merge remote-tracking branch 'origin/master' into llvm6
Diffstat (limited to 'std/buffer.zig')
-rw-r--r--std/buffer.zig14
1 files changed, 11 insertions, 3 deletions
diff --git a/std/buffer.zig b/std/buffer.zig
index 96abaeb762..4f5d281f48 100644
--- a/std/buffer.zig
+++ b/std/buffer.zig
@@ -30,9 +30,9 @@ pub const Buffer = struct {
/// * ::replaceContentsBuffer
/// * ::resize
pub fn initNull(allocator: &Allocator) -> Buffer {
- Buffer {
+ return Buffer {
.list = ArrayList(u8).init(allocator),
- }
+ };
}
/// Must deinitialize with deinit.
@@ -98,14 +98,17 @@ pub const Buffer = struct {
mem.copy(u8, self.list.toSlice()[old_len..], m);
}
+ // TODO: remove, use OutStream for this
pub fn appendFormat(self: &Buffer, comptime format: []const u8, args: ...) -> %void {
return fmt.format(self, append, format, args);
}
+ // TODO: remove, use OutStream for this
pub fn appendByte(self: &Buffer, byte: u8) -> %void {
return self.appendByteNTimes(byte, 1);
}
+ // TODO: remove, use OutStream for this
pub fn appendByteNTimes(self: &Buffer, byte: u8, count: usize) -> %void {
var prev_size: usize = self.len();
%return self.resize(prev_size + count);
@@ -117,7 +120,7 @@ pub const Buffer = struct {
}
pub fn eql(self: &const Buffer, m: []const u8) -> bool {
- mem.eql(u8, self.toSliceConst(), m)
+ return mem.eql(u8, self.toSliceConst(), m);
}
pub fn startsWith(self: &const Buffer, m: []const u8) -> bool {
@@ -136,6 +139,11 @@ pub const Buffer = struct {
%return self.resize(m.len);
mem.copy(u8, self.list.toSlice(), m);
}
+
+ /// For passing to C functions.
+ pub fn ptr(self: &const Buffer) -> &u8 {
+ return self.list.items.ptr;
+ }
};
test "simple Buffer" {