zig/std/str.zig
Andrew Kelley 78d4fb20c4 inline parameters
This replaces the current generic syntax for functions and replaces
it with the concept of inline parameters.

This paves the way for the "all structs anonymous" proposal.

Closes #151.
2016-07-25 22:55:15 -07:00

21 lines
484 B
Zig

const assert = @import("debug.zig").assert;
pub fn eql(a: []const u8, b: []const u8) -> bool {
slice_eql(u8, a, b)
}
pub fn slice_eql(inline 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"));
}