diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-04-18 16:42:56 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-04-18 16:42:56 -0700 |
| commit | f4c7e1bf4971503e2d33af80537aef27ed2e4fe1 (patch) | |
| tree | 1d99e8d2cd97d30870f95f46b2efcf872ccfcc49 /std/str.zig | |
| parent | 5e33175517807c6e50fe66f8d6c65fc094c8e11a (diff) | |
| download | zig-f4c7e1bf4971503e2d33af80537aef27ed2e4fe1.tar.gz zig-f4c7e1bf4971503e2d33af80537aef27ed2e4fe1.zip | |
rearrange standard library a bit
Diffstat (limited to 'std/str.zig')
| -rw-r--r-- | std/str.zig | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/std/str.zig b/std/str.zig new file mode 100644 index 0000000000..7df0c5658a --- /dev/null +++ b/std/str.zig @@ -0,0 +1,34 @@ +const assert = @import("index.zig").assert; + +pub fn len(ptr: &const u8) -> isize { + var count: isize = 0; + while (ptr[count] != 0) { + count += 1; + } + return count; +} + +pub fn from_c_const(str: &const u8) -> []const u8 { + return str[0...len(str)]; +} + +pub fn from_c(str: &u8) -> []u8 { + return str[0...len(str)]; +} + +pub const eql = slice_eql(u8); + +pub fn slice_eql(T: type)(a: []const T, b: []const T) -> bool { + if (a.len != b.len) return false; + for (a) |item, index| { + if (b[index] != item) return false; + } + return true; +} + +#attribute("test") +fn string_equality() { + assert(eql("abcd", "abcd")); + assert(!eql("abcdef", "abZdef")); + assert(!eql("abcdefg", "abcdef")); +} |
