mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
chore: upgrade zig to 0.13.0 (#9965)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Jarred Sumner <jarred@jarredsumner.com> Co-authored-by: Grigory <grigory.orlov.set@gmail.com> Co-authored-by: Dylan Conway <35280289+dylan-conway@users.noreply.github.com> Co-authored-by: Meghan Denny <hello@nektro.net> Co-authored-by: Kenta Iwasaki <63115601+lithdew@users.noreply.github.com> Co-authored-by: John-David Dalton <john.david.dalton@gmail.com> Co-authored-by: Dale Seo <5466341+DaleSeo@users.noreply.github.com> Co-authored-by: Zack Radisic <56137411+zackradisic@users.noreply.github.com> Co-authored-by: paperdave <paperdave@users.noreply.github.com> Co-authored-by: Georgijs Vilums <georgijs.vilums@gmail.com> Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
This commit is contained in:
@@ -8,6 +8,7 @@ const bun = @import("root").bun;
|
||||
const log = bun.Output.scoped(.STR, true);
|
||||
const js_lexer = @import("./js_lexer.zig");
|
||||
const grapheme = @import("./grapheme.zig");
|
||||
const JSC = bun.JSC;
|
||||
|
||||
pub const Encoding = enum {
|
||||
ascii,
|
||||
@@ -46,68 +47,37 @@ pub inline fn removeLeadingDotSlash(slice: []const u8) []const u8 {
|
||||
return slice;
|
||||
}
|
||||
|
||||
pub inline fn w(comptime str: []const u8) [:0]const u16 {
|
||||
if (!@inComptime()) @compileError("strings.w() must be called in a comptime context");
|
||||
comptime var output: [str.len + 1]u16 = undefined;
|
||||
// TODO: remove this
|
||||
pub const w = toUTF16Literal;
|
||||
|
||||
for (str, 0..) |c, i| {
|
||||
output[i] = c;
|
||||
}
|
||||
output[str.len] = 0;
|
||||
|
||||
const Static = struct {
|
||||
pub const literal: [:0]const u16 = output[0 .. output.len - 1 :0];
|
||||
};
|
||||
return Static.literal;
|
||||
}
|
||||
|
||||
pub fn toUTF16Literal(comptime str: []const u8) []const u16 {
|
||||
pub fn toUTF16Literal(comptime str: []const u8) [:0]const u16 {
|
||||
return comptime literal(u16, str);
|
||||
}
|
||||
|
||||
pub inline fn literal(comptime T: type, comptime str: string) []const T {
|
||||
if (!@inComptime()) @compileError("strings.literal() should be called in a comptime context");
|
||||
comptime var output: [str.len]T = undefined;
|
||||
|
||||
for (str, 0..) |c, i| {
|
||||
// TODO(dylan-conway): should we check for non-ascii characters like JSC does with operator""_s
|
||||
output[i] = c;
|
||||
}
|
||||
|
||||
const Static = struct {
|
||||
pub const literal: []const T = output[0..];
|
||||
pub fn literal(comptime T: type, comptime str: []const u8) *const [literalLength(T, str):0]T {
|
||||
if (!@inComptime()) @compileError("strings.literal() must be called in a comptime context");
|
||||
return comptime switch (T) {
|
||||
u8 => brk: {
|
||||
var data: [str.len:0]u8 = undefined;
|
||||
@memcpy(&data, str);
|
||||
const final = data[0..].*;
|
||||
break :brk &final;
|
||||
},
|
||||
u16 => return std.unicode.utf8ToUtf16LeStringLiteral(str),
|
||||
else => @compileError("unsupported type " ++ @typeName(T) ++ " in strings.literal() call."),
|
||||
};
|
||||
return Static.literal;
|
||||
}
|
||||
|
||||
pub inline fn literalBuf(comptime T: type, comptime str: string) [str.len]T {
|
||||
if (!@inComptime()) @compileError("strings.literalBuf() should be called in a comptime context");
|
||||
comptime var output: [str.len]T = undefined;
|
||||
|
||||
for (str, 0..) |c, i| {
|
||||
// TODO(dylan-conway): should we check for non-ascii characters like JSC does with operator""_s
|
||||
output[i] = c;
|
||||
}
|
||||
|
||||
const Static = struct {
|
||||
pub const literal: [str.len]T = output;
|
||||
fn literalLength(comptime T: type, comptime str: string) usize {
|
||||
return comptime switch (T) {
|
||||
u8 => str.len,
|
||||
u16 => std.unicode.calcUtf16LeLen(str) catch unreachable,
|
||||
else => 0, // let other errors report first
|
||||
};
|
||||
return Static.literal;
|
||||
}
|
||||
|
||||
pub inline fn toUTF16LiteralZ(comptime str: []const u8) [:0]const u16 {
|
||||
comptime var output: [str.len + 1]u16 = undefined;
|
||||
|
||||
for (str, 0..) |c, i| {
|
||||
output[i] = c;
|
||||
}
|
||||
output[str.len] = 0;
|
||||
|
||||
const Static = struct {
|
||||
pub const literal: [:0]const u16 = output[0..str.len :0];
|
||||
};
|
||||
return Static.literal;
|
||||
}
|
||||
// TODO: remove this
|
||||
pub const toUTF16LiteralZ = toUTF16Literal;
|
||||
|
||||
pub const OptionalUsize = std.meta.Int(.unsigned, @bitSizeOf(usize) - 1);
|
||||
pub fn indexOfAny(slice: string, comptime str: anytype) ?OptionalUsize {
|
||||
@@ -801,7 +771,7 @@ pub fn hasPrefixComptimeUTF16(self: []const u16, comptime alt: []const u8) bool
|
||||
pub fn hasPrefixComptimeType(comptime T: type, self: []const T, comptime alt: anytype) bool {
|
||||
const rhs = comptime switch (T) {
|
||||
u8 => alt,
|
||||
u16 => switch (std.meta.Child(@TypeOf(alt))) {
|
||||
u16 => switch (bun.meta.Item(@TypeOf(alt))) {
|
||||
u16 => alt,
|
||||
else => w(alt),
|
||||
},
|
||||
@@ -2369,8 +2339,6 @@ pub fn elementLengthLatin1IntoUTF8(comptime Type: type, latin1_: Type) usize {
|
||||
return input_len + total_non_ascii_count;
|
||||
}
|
||||
|
||||
const JSC = bun.JSC;
|
||||
|
||||
pub fn copyLatin1IntoUTF16(comptime Buffer: type, buf_: Buffer, comptime Type: type, latin1_: Type) EncodeIntoResult {
|
||||
var buf = buf_;
|
||||
var latin1 = latin1_;
|
||||
@@ -4913,27 +4881,27 @@ pub fn isIPAddress(input: []const u8) bool {
|
||||
var max_ip_address_buffer: [512]u8 = undefined;
|
||||
if (input.len > max_ip_address_buffer.len) return false;
|
||||
|
||||
var sockaddr: std.os.sockaddr = undefined;
|
||||
var sockaddr: std.posix.sockaddr = undefined;
|
||||
@memset(std.mem.asBytes(&sockaddr), 0);
|
||||
@memcpy(max_ip_address_buffer[0..input.len], input);
|
||||
max_ip_address_buffer[input.len] = 0;
|
||||
|
||||
const ip_addr_str: [:0]const u8 = max_ip_address_buffer[0..input.len :0];
|
||||
|
||||
return bun.c_ares.ares_inet_pton(std.os.AF.INET, ip_addr_str.ptr, &sockaddr) > 0 or bun.c_ares.ares_inet_pton(std.os.AF.INET6, ip_addr_str.ptr, &sockaddr) > 0;
|
||||
return bun.c_ares.ares_inet_pton(std.posix.AF.INET, ip_addr_str.ptr, &sockaddr) > 0 or bun.c_ares.ares_inet_pton(std.posix.AF.INET6, ip_addr_str.ptr, &sockaddr) > 0;
|
||||
}
|
||||
|
||||
pub fn isIPV6Address(input: []const u8) bool {
|
||||
var max_ip_address_buffer: [512]u8 = undefined;
|
||||
if (input.len > max_ip_address_buffer.len) return false;
|
||||
|
||||
var sockaddr: std.os.sockaddr = undefined;
|
||||
var sockaddr: std.posix.sockaddr = undefined;
|
||||
@memset(std.mem.asBytes(&sockaddr), 0);
|
||||
@memcpy(max_ip_address_buffer[0..input.len], input);
|
||||
max_ip_address_buffer[input.len] = 0;
|
||||
|
||||
const ip_addr_str: [:0]const u8 = max_ip_address_buffer[0..input.len :0];
|
||||
return bun.c_ares.ares_inet_pton(std.os.AF.INET6, ip_addr_str.ptr, &sockaddr) > 0;
|
||||
return bun.c_ares.ares_inet_pton(std.posix.AF.INET6, ip_addr_str.ptr, &sockaddr) > 0;
|
||||
}
|
||||
|
||||
pub fn cloneNormalizingSeparators(
|
||||
|
||||
Reference in New Issue
Block a user