This commit is contained in:
Jarred Sumner
2023-09-05 00:44:22 -08:00
parent c5ea98ae56
commit 04a2944eb3
12 changed files with 1012 additions and 907 deletions

View File

@@ -711,7 +711,11 @@ pub inline fn endsWithChar(self: string, char: u8) bool {
pub fn withoutTrailingSlash(this: string) []const u8 {
var href = this;
while (href.len > 1 and href[href.len - 1] == '/') {
while (href.len > 1 and (switch (href[href.len - 1]) {
'/' => true,
'\\' => true,
else => false,
})) {
href.len -= 1;
}
@@ -1484,6 +1488,22 @@ pub fn fromWPath(buf: []u8, utf16: []const u16) [:0]const u8 {
return buf[0..encode_into_result.written :0];
}
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[utf8.len..]) |*c| {
if (c.* == '/') {
c.* = '\\';
}
}
path_to_use = renormalized[0..utf8.len];
}
return toWPath(wbuf, path_to_use);
}
pub fn toWPath(wbuf: []u16, utf8: []const u8) [:0]const u16 {
std.debug.assert(wbuf.len > 0);
var result = bun.simdutf.convert.utf8.to.utf16.with_errors.le(
@@ -4730,3 +4750,4 @@ pub fn concatIfNeeded(
}
std.debug.assert(remain.len == 0);
}