mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
Support async onLoad callbacks in Bun.plugin
This commit is contained in:
@@ -324,6 +324,43 @@ pub fn copyLowercase(in: string, out: []u8) string {
|
||||
return out[0..in.len];
|
||||
}
|
||||
|
||||
pub fn copyLowercaseIfNeeded(in: string, out: []u8) string {
|
||||
var in_slice: string = in;
|
||||
var out_slice: []u8 = out[0..in.len];
|
||||
var any = false;
|
||||
|
||||
begin: while (out_slice.len > 0) {
|
||||
for (in_slice) |c, i| {
|
||||
switch (c) {
|
||||
'A'...'Z' => {
|
||||
@memcpy(out_slice.ptr, in_slice.ptr, i);
|
||||
out_slice[i] = std.ascii.toLower(c);
|
||||
const end = i + 1;
|
||||
if (end >= out_slice.len) break :begin;
|
||||
in_slice = in_slice[end..];
|
||||
out_slice = out_slice[end..];
|
||||
any = true;
|
||||
continue :begin;
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
|
||||
if (!any) {
|
||||
return in;
|
||||
}
|
||||
|
||||
@memcpy(out_slice.ptr, in_slice.ptr, in_slice.len);
|
||||
break :begin;
|
||||
}
|
||||
|
||||
if (!any) {
|
||||
return in;
|
||||
}
|
||||
|
||||
return out[0..in.len];
|
||||
}
|
||||
|
||||
test "indexOf" {
|
||||
const fixtures = .{
|
||||
.{
|
||||
|
||||
Reference in New Issue
Block a user