Support async onLoad callbacks in Bun.plugin

This commit is contained in:
Jarred Sumner
2022-09-05 23:05:22 -07:00
parent d2397b60e7
commit 11aa17a57c
22 changed files with 1670 additions and 709 deletions

View File

@@ -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 = .{
.{