aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-11-04 18:41:40 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-11-04 18:41:40 -0700
commitd44abd8e4d6d46b41862eeeee317d10de73790da (patch)
treec35d5cd72a6c9c50f5c5374938bf318603cd2634
parent5c38b6c3557ac06f5811d5a82ce2314916d8eaee (diff)
downloadbun-d44abd8e4d6d46b41862eeeee317d10de73790da.tar.gz
bun-d44abd8e4d6d46b41862eeeee317d10de73790da.tar.zst
bun-d44abd8e4d6d46b41862eeeee317d10de73790da.zip
Update string_immutable.zig
-rw-r--r--src/string_immutable.zig7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig
index e957eacab..cb33e9d59 100644
--- a/src/string_immutable.zig
+++ b/src/string_immutable.zig
@@ -547,6 +547,10 @@ pub inline fn wtf8ByteSequenceLength(first_byte: u8) u3 {
};
}
+/// Convert potentially ill-formed UTF-8 or UTF-16 bytes to a Unicode Codepoint.
+/// Invalid codepoints are replaced with `zero` parameter
+/// This is a clone of esbuild's decodeWTF8Rune
+/// which was a clone of golang's "utf8.DecodeRune" that was modified to decode using WTF-8 instead.
/// Asserts a multi-byte codepoint
pub inline fn decodeWTF8RuneTMultibyte(p: *const [4]u8, len: u3, comptime T: type, comptime zero: T) T {
std.debug.assert(len > 1);
@@ -580,6 +584,9 @@ pub inline fn decodeWTF8RuneTMultibyte(p: *const [4]u8, len: u3, comptime T: typ
unreachable;
}
+/// Convert potentially ill-formed UTF-8 or UTF-16 bytes to a Unicode Codepoint.
+/// - Invalid codepoints are replaced with `zero` parameter
+/// - Null bytes return 0
pub fn decodeWTF8RuneT(p: *const [4]u8, len: u3, comptime T: type, comptime zero: T) T {
if (len == 0) return zero;
if (len == 1) return p[0];