mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 19:38:58 +00:00
further!
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user