pub const Utf8View = struct bytes: []const u8pub fn init(s: []const u8) !Utf8Viewpub fn initUnchecked(s: []const u8) Utf8Viewpub inline fn initComptime(comptime s: []const u8) Utf8Viewpub fn iterator(s: Utf8View) Utf8Iterator363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392pub const Utf8View = struct {
bytes: []const u8,
pub fn init(s: []const u8) !Utf8View {
if (!utf8ValidateSlice(s)) {
return error.InvalidUtf8;
}
return initUnchecked(s);
}
pub fn initUnchecked(s: []const u8) Utf8View {
return Utf8View{ .bytes = s };
}
pub inline fn initComptime(comptime s: []const u8) Utf8View {
return comptime if (init(s)) |r| r else |err| switch (err) {
error.InvalidUtf8 => {
@compileError("invalid utf8");
},
};
}
pub fn iterator(s: Utf8View) Utf8Iterator {
return Utf8Iterator{
.bytes = s.bytes,
.i = 0,
};
}
}
Utf8View iterates the code points of a utf-8 encoded string.