diff options
Diffstat (limited to 'src/string_immutable.zig')
-rw-r--r-- | src/string_immutable.zig | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig index a68059aef..923d860cc 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -660,6 +660,21 @@ pub const CodepointIterator = struct { return if (!(it.i > it.bytes.len)) it.bytes[it.i - cp_len .. it.i] else ""; } + pub fn needsUTF8Decoding(slice: string) bool { + var it = CodepointIterator{ .bytes = slice, .i = 0 }; + + while (true) { + const part = it.nextCodepointSlice(); + it.width = @intCast(u3, part.len); + @setRuntimeSafety(false); + switch (it.width) { + 0 => return false, + 1 => continue, + else => return true, + } + } + } + pub fn nextCodepoint(it: *CodepointIterator) CodePoint { const slice = it.nextCodepointSlice(); it.width = @intCast(u3, slice.len); |