mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
windows: random things (#9046)
* random things * fix reliability of loading napi stuff * fix posix build * a
This commit is contained in:
@@ -17,6 +17,13 @@ pub const Encoding = enum {
|
||||
utf16,
|
||||
};
|
||||
|
||||
/// Returned by classification functions that do not discriminate between utf8 and ascii.
|
||||
pub const EncodingNonAscii = enum {
|
||||
utf8,
|
||||
utf16,
|
||||
latin1,
|
||||
};
|
||||
|
||||
pub inline fn containsChar(self: string, char: u8) bool {
|
||||
return indexOfChar(self, char) != null;
|
||||
}
|
||||
@@ -1774,17 +1781,8 @@ pub fn toWPathNormalizeAutoExtend(wbuf: []u16, utf8: []const u8) [:0]const u16 {
|
||||
|
||||
pub fn toWPathNormalized(wbuf: []u16, utf8: []const u8) [:0]const u16 {
|
||||
var renormalized: [bun.MAX_PATH_BYTES]u8 = undefined;
|
||||
var path_to_use = utf8;
|
||||
|
||||
if (bun.strings.containsChar(utf8, '/')) {
|
||||
@memcpy(renormalized[0..utf8.len], utf8);
|
||||
for (renormalized[0..utf8.len]) |*c| {
|
||||
if (c.* == '/') {
|
||||
c.* = '\\';
|
||||
}
|
||||
}
|
||||
path_to_use = renormalized[0..utf8.len];
|
||||
}
|
||||
var path_to_use = normalizeSlashesOnly(&renormalized, utf8, '\\');
|
||||
|
||||
// is there a trailing slash? Let's remove it before converting to UTF-16
|
||||
if (path_to_use.len > 3 and bun.path.isSepAny(path_to_use[path_to_use.len - 1])) {
|
||||
@@ -1794,6 +1792,23 @@ pub fn toWPathNormalized(wbuf: []u16, utf8: []const u8) [:0]const u16 {
|
||||
return toWPath(wbuf, path_to_use);
|
||||
}
|
||||
|
||||
pub fn normalizeSlashesOnly(buf: []u8, utf8: []const u8, comptime desired_slash: u8) []const u8 {
|
||||
comptime std.debug.assert(desired_slash == '/' or desired_slash == '\\');
|
||||
const undesired_slash = if (desired_slash == '/') '\\' else '/';
|
||||
|
||||
if (bun.strings.containsChar(utf8, undesired_slash)) {
|
||||
@memcpy(buf[0..utf8.len], utf8);
|
||||
for (buf[0..utf8.len]) |*c| {
|
||||
if (c.* == undesired_slash) {
|
||||
c.* = desired_slash;
|
||||
}
|
||||
}
|
||||
return buf[0..utf8.len];
|
||||
}
|
||||
|
||||
return utf8;
|
||||
}
|
||||
|
||||
pub fn toWDirNormalized(wbuf: []u16, utf8: []const u8) [:0]const u16 {
|
||||
var renormalized: [bun.MAX_PATH_BYTES]u8 = undefined;
|
||||
var path_to_use = utf8;
|
||||
|
||||
Reference in New Issue
Block a user