aboutsummaryrefslogtreecommitdiff
path: root/std/std.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-01-08 17:52:45 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-01-08 17:52:45 -0700
commitd14a31100f3f4e7b8d43c8ad794a82da36532aa7 (patch)
tree9cb70f9785427c24499dff91bc3383837c7de78d /std/std.zig
parent2a8d6af7ba9dcea5f13e306f2d032f3f344950af (diff)
downloadzig-d14a31100f3f4e7b8d43c8ad794a82da36532aa7.tar.gz
zig-d14a31100f3f4e7b8d43c8ad794a82da36532aa7.zip
implement unknown size array indexing and slicing
Diffstat (limited to 'std/std.zig')
-rw-r--r--std/std.zig18
1 files changed, 7 insertions, 11 deletions
diff --git a/std/std.zig b/std/std.zig
index da412e3f90..82471748b1 100644
--- a/std/std.zig
+++ b/std/std.zig
@@ -26,7 +26,7 @@ pub fn fprint_str(fd: isize, str: []const u8) -> isize {
pub fn print_u64(x: u64) -> isize {
// TODO use max_u64_base10_digits instead of hardcoding 20
var buf: [20]u8;
- const len = buf_print_u64(buf.ptr, x);
+ const len = buf_print_u64(buf, x);
return write(stdout_fileno, buf.ptr, len);
}
@@ -35,7 +35,7 @@ pub fn print_u64(x: u64) -> isize {
pub fn print_i64(x: i64) -> isize {
// TODO use max_u64_base10_digits instead of hardcoding 20
var buf: [20]u8;
- const len = buf_print_i64(buf.ptr, x);
+ const len = buf_print_i64(buf, x);
return write(stdout_fileno, buf.ptr, len);
}
@@ -56,8 +56,7 @@ pub fn parse_u64(buf: []u8, radix: u8, result: &u64) -> bool {
var i : #typeof(buf.len) = 0;
while (i < buf.len) {
- // TODO array indexing operator
- const c = buf.ptr[i];
+ const c = buf[i];
const digit = char_to_digit(c);
if (digit > radix) {
@@ -100,20 +99,16 @@ fn char_to_digit(c: u8) -> u8 {
const max_u64_base10_digits: usize = 20;
-// TODO use an array for out_buf instead of pointer. this should give bounds checking in
-// debug mode and length can get optimized out in release mode. requires array slicing syntax
-// for the buf_print_u64 call.
-fn buf_print_i64(out_buf: &u8, x: i64) -> usize {
+fn buf_print_i64(out_buf: []u8, x: i64) -> usize {
if (x < 0) {
out_buf[0] = '-';
- return 1 + buf_print_u64(&out_buf[1], ((-(x + 1)) as u64) + 1);
+ return 1 + buf_print_u64(out_buf[1...], ((-(x + 1)) as u64) + 1);
} else {
return buf_print_u64(out_buf, x as u64);
}
}
-// TODO use an array for out_buf instead of pointer.
-fn buf_print_u64(out_buf: &u8, x: u64) -> usize {
+fn buf_print_u64(out_buf: []u8, x: u64) -> usize {
var buf: [max_u64_base10_digits]u8;
var a = x;
var index = buf.len;
@@ -130,6 +125,7 @@ fn buf_print_u64(out_buf: &u8, x: u64) -> usize {
const len = buf.len - index;
// TODO memcpy intrinsic
+ // @memcpy(out_buf, buf, len);
var i: usize = 0;
while (i < len) {
out_buf[i] = buf[index + i];