refactor: move all zg LetterCasing usage to Buffer.unicode

This commit is contained in:
CJ van den Berg 2025-11-23 22:15:13 +01:00
parent 57c5066451
commit 2ff0521040
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
3 changed files with 26 additions and 10 deletions

View file

@ -6182,7 +6182,7 @@ pub const Editor = struct {
const sfa_allocator = sfa.get();
const cut_text = copy_selection(root, sel.*, sfa_allocator, self.metrics) catch return error.Stop;
defer sfa_allocator.free(cut_text);
const ucased = Buffer.unicode.get_letter_casing().toUpperStr(sfa_allocator, cut_text) catch return error.Stop;
const ucased = Buffer.unicode.to_upper(sfa_allocator, cut_text) catch return error.Stop;
defer sfa_allocator.free(ucased);
root = try self.delete_selection(root, cursel, allocator);
root = self.insert(root, cursel, ucased, allocator) catch return error.Stop;
@ -6211,7 +6211,7 @@ pub const Editor = struct {
const sfa_allocator = sfa.get();
const cut_text = copy_selection(root, sel.*, sfa_allocator, self.metrics) catch return error.Stop;
defer sfa_allocator.free(cut_text);
const ucased = Buffer.unicode.get_letter_casing().toLowerStr(sfa_allocator, cut_text) catch return error.Stop;
const ucased = Buffer.unicode.to_lower(sfa_allocator, cut_text) catch return error.Stop;
defer sfa_allocator.free(ucased);
root = try self.delete_selection(root, cursel, buffer_allocator);
root = self.insert(root, cursel, ucased, buffer_allocator) catch return error.Stop;
@ -6241,11 +6241,7 @@ pub const Editor = struct {
root.write_range(sel.*, &range.writer, null, self.metrics) catch return error.Stop;
const bytes = range.written();
const letter_casing = Buffer.unicode.get_letter_casing();
const flipped = if (letter_casing.isLowerStr(bytes))
letter_casing.toUpperStr(self.allocator, bytes) catch return error.Stop
else
letter_casing.toLowerStr(self.allocator, bytes) catch return error.Stop;
const flipped = Buffer.unicode.switch_case(self.allocator, bytes) catch return error.Stop;
defer self.allocator.free(flipped);
root = try self.delete_selection(root, cursel, allocator);

View file

@ -248,9 +248,9 @@ pub fn Create(options: type) type {
}
fn prefix_compare_icase(allocator: std.mem.Allocator, prefix: []const u8, str: []const u8) error{OutOfMemory}!bool {
const icase_prefix = Buffer.unicode.get_letter_casing().toLowerStr(allocator, prefix) catch try allocator.dupe(u8, prefix);
const icase_prefix = Buffer.unicode.case_fold(allocator, prefix) catch try allocator.dupe(u8, prefix);
defer allocator.free(icase_prefix);
const icase_str = Buffer.unicode.get_letter_casing().toLowerStr(allocator, str) catch try allocator.dupe(u8, str);
const icase_str = Buffer.unicode.case_fold(allocator, str) catch try allocator.dupe(u8, str);
defer allocator.free(icase_str);
if (icase_str.len < icase_prefix.len) return false;
return std.mem.eql(u8, icase_prefix, icase_str[0..icase_prefix.len]);