diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-06-02 04:03:25 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-06-02 04:04:23 -0400 |
| commit | f06bce5ddaea368040560f584170aee2864fa399 (patch) | |
| tree | 61937f83c19f0090cd9daadfa570504801dc24f8 /std/cstr.zig | |
| parent | 7b386ea24285db2fbc40233a232cb294dddf9879 (diff) | |
| download | zig-f06bce5ddaea368040560f584170aee2864fa399.tar.gz zig-f06bce5ddaea368040560f584170aee2864fa399.zip | |
introduce [*] for unknown length pointers
See #770
Currently it does not have any different behavior than `*`
but it is now recommended to use `[*]` for unknown length
pointers to be future-proof.
Instead of [ * ] being separate tokens as the proposal
suggested, this commit implements `[*]` as a single token.
Diffstat (limited to 'std/cstr.zig')
| -rw-r--r-- | std/cstr.zig | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/std/cstr.zig b/std/cstr.zig index dfbfb8047f..d60adf8faa 100644 --- a/std/cstr.zig +++ b/std/cstr.zig @@ -9,13 +9,13 @@ pub const line_sep = switch (builtin.os) { else => "\n", }; -pub fn len(ptr: *const u8) usize { +pub fn len(ptr: [*]const u8) usize { var count: usize = 0; while (ptr[count] != 0) : (count += 1) {} return count; } -pub fn cmp(a: *const u8, b: *const u8) i8 { +pub fn cmp(a: [*]const u8, b: [*]const u8) i8 { var index: usize = 0; while (a[index] == b[index] and a[index] != 0) : (index += 1) {} if (a[index] > b[index]) { @@ -27,11 +27,11 @@ pub fn cmp(a: *const u8, b: *const u8) i8 { } } -pub fn toSliceConst(str: *const u8) []const u8 { +pub fn toSliceConst(str: [*]const u8) []const u8 { return str[0..len(str)]; } -pub fn toSlice(str: *u8) []u8 { +pub fn toSlice(str: [*]u8) []u8 { return str[0..len(str)]; } |
