diff options
author | 2021-08-14 02:39:44 -0700 | |
---|---|---|
committer | 2021-08-14 02:39:44 -0700 | |
commit | 16c76743048ef905269e2711cb0148ecc4e57f3f (patch) | |
tree | a8fb11b55767945a47e92120179f2f762b1f8e99 /src/string_immutable.zig | |
parent | f59892f647ceef1c05e40c9cdef4f79d0a530c2f (diff) | |
download | bun-16c76743048ef905269e2711cb0148ecc4e57f3f.tar.gz bun-16c76743048ef905269e2711cb0148ecc4e57f3f.tar.zst bun-16c76743048ef905269e2711cb0148ecc4e57f3f.zip |
lots
Former-commit-id: 0b8128cb3b4db02f9d33331b4c2c1b595156e6c8
Diffstat (limited to '')
-rw-r--r-- | src/string_immutable.zig | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 5e651fc5d..618657a64 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -217,7 +217,7 @@ pub fn eqlComptime(self: string, comptime alt: anytype) bool { return (self.len == alt.len) and first == std.mem.readIntNative(u64, self[0..8]) and second == std.mem.readIntNative(u64, self[8..16]); }, else => { - @compileError(alt ++ " is too long."); + @compileError(alt ++ " is too long."); }, } } @@ -499,6 +499,21 @@ pub const CodepointIterator = struct { return it.c; } + pub fn nextCodepointNoReturn(it: *CodepointIterator) void { + const slice = it.nextCodepointSlice(); + it.width = @intCast(u3, slice.len); + @setRuntimeSafety(false); + + it.c = switch (it.width) { + 0 => -1, + 1 => @intCast(CodePoint, slice[0]), + 2 => @intCast(CodePoint, std.unicode.utf8Decode2(slice) catch unreachable), + 3 => @intCast(CodePoint, std.unicode.utf8Decode3(slice) catch unreachable), + 4 => @intCast(CodePoint, std.unicode.utf8Decode4(slice) catch unreachable), + else => unreachable, + }; + } + /// Look ahead at the next n codepoints without advancing the iterator. /// If fewer than n codepoints are available, then return the remainder of the string. pub fn peek(it: *CodepointIterator, n: usize) []const u8 { |