From 11aa17a57cc679d34e8e6f6f7aa665f565cb7305 Mon Sep 17 00:00:00 2001
From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Date: Mon, 5 Sep 2022 23:05:22 -0700
Subject: Support async `onLoad` callbacks in `Bun.plugin`
---
src/string_immutable.zig | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
(limited to 'src/string_immutable.zig')
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 = .{
.{
--
cgit v1.2.3
Unnamed repository; edit this file 'description' to name the repository. | |