diff options
author | 2023-01-19 21:00:53 -0800 | |
---|---|---|
committer | 2023-01-19 21:00:53 -0800 | |
commit | f993975ae6e94e367f30f66ddba9c69a693f8aa4 (patch) | |
tree | 88b36aaba0bb3a8c792ab6e974dd4f3ec0deef29 /src/bun.js/bindings/bindings.zig | |
parent | 53f7bd32d8872d4a4def120b67ddf180bb0c23b0 (diff) | |
download | bun-f993975ae6e94e367f30f66ddba9c69a693f8aa4.tar.gz bun-f993975ae6e94e367f30f66ddba9c69a693f8aa4.tar.zst bun-f993975ae6e94e367f30f66ddba9c69a693f8aa4.zip |
make this code easier to read
Diffstat (limited to 'src/bun.js/bindings/bindings.zig')
-rw-r--r-- | src/bun.js/bindings/bindings.zig | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index a7bede295..49e0fad23 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -91,6 +91,23 @@ pub const ZigString = extern struct { ptr: [*]const u8, len: usize, + pub const ByteString = union(enum) { + latin1: []const u8, + utf16: []const u16, + }; + + pub inline fn as(this: ZigString) ByteString { + return if (this.is16Bit()) .{ .utf16 = this.utf16SliceAligned() } else .{ .latin1 = this.slice() }; + } + + pub fn encode(this: ZigString, encoding: JSC.Node.Encoding) []u8 { + return switch (this.as()) { + inline else => |repr| switch (encoding) { + inline else => |enc| JSC.WebCore.Encoder.constructFrom(std.meta.Child(@TypeOf(repr)), repr, enc), + }, + }; + } + /// This function is not optimized! pub fn eqlCaseInsensitive(this: ZigString, other: ZigString) bool { var fallback = std.heap.stackFallback(1024, bun.default_allocator); |