zig/std/str.zig

22 lines
489 B
Zig
Raw Normal View History

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