Portable SIMD byte and UTF-8 code point counts adapted from bytecount
///|
test "count bytes in a view" {
let input = b"|cat dog fox|"
assert_eq(@bytecount.count(input[1:12], b' '), 2)
}
///|
test "count UTF-8 code points" {
assert_eq(@bytecount.num_chars(b"A\xC3\xA9\xF0\x9F\x98\x80"), 3)
}fn count(data : BytesView, needle : Byte) -> Inttest {
assert_eq(@bytecount.count(b"one two three", b' '), 2)
}fn naive_count(data : BytesView, needle : Byte) -> Intfn naive_count_32(data : BytesView, needle : Byte) -> Intfn naive_num_chars(data : BytesView) -> Intfn num_chars(data : BytesView) -> Inttest {
assert_eq(@bytecount.num_chars(b"A\xC3\xA9\xF0\x9F\x98\x80"), 3)
}Install
Download zipPortable SIMD byte and UTF-8 code point counts adapted from bytecount