aboutsummaryrefslogtreecommitdiff
path: root/src/string_immutable.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-09-05 23:05:22 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-09-05 23:05:22 -0700
commit11aa17a57cc679d34e8e6f6f7aa665f565cb7305 (patch)
treeccb9a605cb4bcc42c6b2665ddbf8d04af72d94c7 /src/string_immutable.zig
parentd2397b60e79e4386c6a7b7a9783a6f8e379a5ae0 (diff)
downloadbun-11aa17a57cc679d34e8e6f6f7aa665f565cb7305.tar.gz
bun-11aa17a57cc679d34e8e6f6f7aa665f565cb7305.tar.zst
bun-11aa17a57cc679d34e8e6f6f7aa665f565cb7305.zip
Support async `onLoad` callbacks in `Bun.plugin`
Diffstat (limited to 'src/string_immutable.zig')
-rw-r--r--src/string_immutable.zig37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig
index 48d591eff..acf9d057c 100644
--- a/src/string_immutable.zig
+++ b/src/string_immutable.zig
@@ -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 = .{
.{