| author | |
| committer | |
| log | 01c46eef3a7e4fd5a96f364541c539746ae1ea3b |
| tree | 447b4bf1086aae9a01844abcb9e55156d3007c26 |
| parent | 6f0f357ee43fc02ad2dc1eb44ab127c0d741282c |
6 files changed, 32 insertions(+), 20 deletions(-)
CMakeLists.txt+1| ... | ... | @@ -206,6 +206,7 @@ install(FILES "${CMAKE_SOURCE_DIR}/std/io.zig" DESTINATION "${ZIG_STD_DEST}") |
| 206 | 206 | install(FILES "${CMAKE_SOURCE_DIR}/std/net.zig" DESTINATION "${ZIG_STD_DEST}") |
| 207 | 207 | install(FILES "${CMAKE_SOURCE_DIR}/std/os.zig" DESTINATION "${ZIG_STD_DEST}") |
| 208 | 208 | install(FILES "${CMAKE_SOURCE_DIR}/std/str.zig" DESTINATION "${ZIG_STD_DEST}") |
| 209 | install(FILES "${CMAKE_SOURCE_DIR}/std/cstr.zig" DESTINATION "${ZIG_STD_DEST}") | |
| 209 | 210 | install(FILES "${CMAKE_SOURCE_DIR}/std/linux.zig" DESTINATION "${ZIG_STD_DEST}") |
| 210 | 211 | install(FILES "${CMAKE_SOURCE_DIR}/std/errno.zig" DESTINATION "${ZIG_STD_DEST}") |
| 211 | 212 | install(FILES "${CMAKE_SOURCE_DIR}/std/rand.zig" DESTINATION "${ZIG_STD_DEST}") |
std/bootstrap.zig+2-2| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | |
| 3 | 3 | const root = @import("@root"); |
| 4 | 4 | const linux = @import("linux.zig"); |
| 5 | const str = @import("str.zig"); | |
| 5 | const cstr = @import("cstr.zig"); | |
| 6 | 6 | |
| 7 | 7 | const want_start_symbol = switch(@compile_var("os")) { |
| 8 | 8 | linux => true, |
| ... | ... | @@ -34,7 +34,7 @@ fn call_main() -> %void { |
| 34 | 34 | var args: [argc][]u8 = undefined; |
| 35 | 35 | for (args) |arg, i| { |
| 36 | 36 | const ptr = argv[i]; |
| 37 | args[i] = ptr[0...str.len(ptr)]; | |
| 37 | args[i] = ptr[0...cstr.len(ptr)]; | |
| 38 | 38 | } |
| 39 | 39 | return root.main(args); |
| 40 | 40 | } |
std/cstr.zig created+26| ... | ... | @@ -0,0 +1,26 @@ |
| 1 | // TODO fix https://github.com/andrewrk/zig/issues/140 | |
| 2 | // and then make this able to run at compile time | |
| 3 | #static_eval_enable(false) | |
| 4 | pub fn len(ptr: &const u8) -> isize { | |
| 5 | var count: isize = 0; | |
| 6 | while (ptr[count] != 0; count += 1) {} | |
| 7 | return count; | |
| 8 | } | |
| 9 | ||
| 10 | // TODO fix https://github.com/andrewrk/zig/issues/140 | |
| 11 | // and then make this able to run at compile time | |
| 12 | #static_eval_enable(false) | |
| 13 | pub fn cmp(a: &const u8, b: &const u8) -> i32 { | |
| 14 | var index: isize = 0; | |
| 15 | while (a[index] == b[index] && a[index] != 0; index += 1) {} | |
| 16 | return a[index] - b[index]; | |
| 17 | } | |
| 18 | ||
| 19 | pub fn to_slice_const(str: &const u8) -> []const u8 { | |
| 20 | return str[0...len(str)]; | |
| 21 | } | |
| 22 | ||
| 23 | pub fn to_slice(str: &u8) -> []u8 { | |
| 24 | return str[0...len(str)]; | |
| 25 | } | |
| 26 |
std/index.zig+1| ... | ... | @@ -3,6 +3,7 @@ pub const io = @import("io.zig"); |
| 3 | 3 | pub const os = @import("os.zig"); |
| 4 | 4 | pub const math = @import("math.zig"); |
| 5 | 5 | pub const str = @import("str.zig"); |
| 6 | pub const cstr = @import("cstr.zig"); | |
| 6 | 7 | pub const net = @import("net.zig"); |
| 7 | 8 | |
| 8 | 9 | pub fn assert(b: bool) { |
std/str.zig-17| ... | ... | @@ -1,22 +1,5 @@ |
| 1 | 1 | const assert = @import("index.zig").assert; |
| 2 | 2 | |
| 3 | // fix https://github.com/andrewrk/zig/issues/140 | |
| 4 | // and then make this able to run at compile time | |
| 5 | #static_eval_enable(false) | |
| 6 | pub fn len(ptr: &const u8) -> isize { | |
| 7 | var count: isize = 0; | |
| 8 | while (ptr[count] != 0; count += 1) {} | |
| 9 | return count; | |
| 10 | } | |
| 11 | ||
| 12 | pub fn from_c_const(str: &const u8) -> []const u8 { | |
| 13 | return str[0...len(str)]; | |
| 14 | } | |
| 15 | ||
| 16 | pub fn from_c(str: &u8) -> []u8 { | |
| 17 | return str[0...len(str)]; | |
| 18 | } | |
| 19 | ||
| 20 | 3 | pub const eql = slice_eql(u8); |
| 21 | 4 | |
| 22 | 5 | pub fn slice_eql(T: type)(a: []const T, b: []const T) -> bool { |
test/self_hosted.zig+2-1| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const assert = std.assert; |
| 3 | 3 | const str = std.str; |
| 4 | const cstr = std.cstr; | |
| 4 | 5 | const other = @import("other.zig"); |
| 5 | 6 | |
| 6 | 7 | #attribute("test") |
| ... | ... | @@ -1557,7 +1558,7 @@ fn c_string_concatenation() { |
| 1557 | 1558 | const a = c"OK" ++ c" IT " ++ c"WORKED"; |
| 1558 | 1559 | const b = c"OK IT WORKED"; |
| 1559 | 1560 | |
| 1560 | const len = str.len(b); | |
| 1561 | const len = cstr.len(b); | |
| 1561 | 1562 | const len_with_null = len + 1; |
| 1562 | 1563 | {var i: i32 = 0; while (i < len_with_null; i += 1) { |
| 1563 | 1564 | assert(a[i] == b[i]); |