initial commit

This commit is contained in:
2025-12-26 18:42:04 +01:00
commit d8d9ddfc53
52 changed files with 16863 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
const std = @import("std");
/// Convert a string to lowercase using a pre-allocated buffer.
/// Returns null if the buffer is too small.
pub fn toLower(s: []const u8, buf: []u8) ?[]const u8 {
if (s.len > buf.len) return null;
for (s, 0..) |c, i| {
buf[i] = std.ascii.toLower(c);
}
return buf[0..s.len];
}
test "toLower" {
const testing = std.testing;
var buf: [64]u8 = undefined;
try testing.expectEqualStrings("hello", toLower("HELLO", &buf).?);
try testing.expectEqualStrings("hello", toLower("hello", &buf).?);
try testing.expectEqualStrings("hello123", toLower("HeLLo123", &buf).?);
// Buffer too small
var small_buf: [2]u8 = undefined;
try testing.expect(toLower("hello", &small_buf) == null);
}