zig/std/str.zig

22 lines
495 B
Zig
Raw Normal View History

const assert = @import("debug.zig").assert;
2016-04-19 07:42:56 +08:00
pub fn eql(a: []const u8, b: []const u8) -> bool {
2016-08-17 13:42:50 +08:00
sliceEql(u8, a, b)
}
2016-04-19 07:42:56 +08:00
2016-08-17 13:42:50 +08:00
pub fn sliceEql(inline T: type, a: []const T, b: []const T) -> bool {
2016-04-19 07:42:56 +08:00
if (a.len != b.len) return false;
for (a) |item, index| {
if (b[index] != item) return false;
}
return true;
}
fn testStringEquality() {
@setFnTest(this, true);
2016-04-19 07:42:56 +08:00
assert(eql("abcd", "abcd"));
assert(!eql("abcdef", "abZdef"));
assert(!eql("abcdefg", "abcdef"));
}