pub const Wtf8View = struct bytes: []const u8pub fn init(s: []const u8) errorpub fn initUnchecked(s: []const u8) Wtf8Viewpub inline fn initComptime(comptime s: []const u8) Wtf8Viewpub fn iterator(s: Wtf8View) Wtf8Iterator1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750pub const Wtf8View = struct {
bytes: []const u8,
pub fn init(s: []const u8) error{InvalidWtf8}!Wtf8View {
if (!wtf8ValidateSlice(s)) {
return error.InvalidWtf8;
}
return initUnchecked(s);
}
pub fn initUnchecked(s: []const u8) Wtf8View {
return Wtf8View{ .bytes = s };
}
pub inline fn initComptime(comptime s: []const u8) Wtf8View {
return comptime if (init(s)) |r| r else |err| switch (err) {
error.InvalidWtf8 => {
@compileError("invalid wtf8");
},
};
}
pub fn iterator(s: Wtf8View) Wtf8Iterator {
return Wtf8Iterator{
.bytes = s.bytes,
.i = 0,
};
}
}
Wtf8View iterates the code points of a WTF-8 encoded string, including surrogate halves.