fix: use a partial write capable case folding writer in Buffer.find_all_ranges

This fixes case insensitive search. Previously the case folding would fail on
input slices that contain partial utf8 sequences, which is normal in the
buffer write process design. Now these partial utf8 sequences are not consumed
and instead pushed to the next write call where they will be completed from the
main buffer contents.
This commit is contained in:
CJ van den Berg 2025-11-26 09:56:39 +01:00
parent 68b17301cd
commit 99f9f95dbc
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 71 additions and 7 deletions

View file

@ -989,9 +989,9 @@ const Node = union(enum) {
.case_folded => {
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..];
const folded = unicode.case_folded_write_partial(&writer, input[0..input_consume_size]) catch return error.WriteFailed;
ctx.rest = ctx.buf[0 .. ctx.rest.len + folded.len];
input = input[folded.len..];
},
}