refactor: implement find_all_ranges mode .case_folded

This commit is contained in:
CJ van den Berg 2025-11-25 21:43:12 +01:00
parent 37428bd698
commit 3ebe68a384
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -947,6 +947,7 @@ const Node = union(enum) {
pub const FindAllCallback = fn (data: *anyopaque, begin_row: usize, begin_col: usize, end_row: usize, end_col: usize) error{Stop}!void; pub const FindAllCallback = fn (data: *anyopaque, begin_row: usize, begin_col: usize, end_row: usize, end_col: usize) error{Stop}!void;
pub fn find_all_ranges(self: *const Node, pattern: []const u8, data: *anyopaque, callback: *const FindAllCallback, mode: FindMode, allocator: Allocator) error{ OutOfMemory, Stop }!void { pub fn find_all_ranges(self: *const Node, pattern: []const u8, data: *anyopaque, callback: *const FindAllCallback, mode: FindMode, allocator: Allocator) error{ OutOfMemory, Stop }!void {
const Ctx = struct { const Ctx = struct {
allocator: std.mem.Allocator,
pattern: []const u8, pattern: []const u8,
data: *anyopaque, data: *anyopaque,
callback: *const FindAllCallback, callback: *const FindAllCallback,
@ -985,7 +986,11 @@ const Node = union(enum) {
input = input[input_consume_size..]; input = input[input_consume_size..];
}, },
.case_folded => { .case_folded => {
@panic("unimplemented"); const input_consume_size = @min(ctx.buf.len - ctx.rest.len, input.len);
var writer = std.Io.Writer.fixed(ctx.buf[ctx.rest.len..]);
unicode.case_folded_write(&writer, input[0..input_consume_size]) catch return error.WriteFailed;
ctx.rest = ctx.buf[0 .. ctx.rest.len + writer.end];
input = input[input_consume_size..];
}, },
} }
@ -1030,6 +1035,7 @@ const Node = union(enum) {
} }
}; };
var ctx: Ctx = .{ var ctx: Ctx = .{
.allocator = allocator,
.pattern = pattern, .pattern = pattern,
.data = data, .data = data,
.callback = callback, .callback = callback,