diff options
| author | 2026-02-06 13:07:03 -0500 | |
|---|---|---|
| committer | 2026-02-06 13:07:03 -0500 | |
| commit | b823a49b6a57bc1736b33a0816b42aaaf86cf839 (patch) | |
| tree | 533a2ffff737ba2826456fecb01bf3eb187b872a /src/CaseFolding.zig | |
| parent | Slightly better hash reduction for comptime_map (diff) | |
| download | zg-b823a49b6a57bc1736b33a0816b42aaaf86cf839.tar.gz zg-b823a49b6a57bc1736b33a0816b42aaaf86cf839.tar.xz zg-b823a49b6a57bc1736b33a0816b42aaaf86cf839.zip | |
zg module, casing improvements
Diffstat (limited to 'src/CaseFolding.zig')
| -rw-r--r-- | src/CaseFolding.zig | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/CaseFolding.zig b/src/CaseFolding.zig index d69cddc..b7aa020 100644 --- a/src/CaseFolding.zig +++ b/src/CaseFolding.zig | |||
| @@ -103,7 +103,16 @@ pub fn compatCaselessMatch( | |||
| 103 | a: []const u8, | 103 | a: []const u8, |
| 104 | b: []const u8, | 104 | b: []const u8, |
| 105 | ) Allocator.Error!bool { | 105 | ) Allocator.Error!bool { |
| 106 | if (ascii.isAsciiOnly(a) and ascii.isAsciiOnly(b)) return std.ascii.eqlIgnoreCase(a, b); | 106 | var a_in = a; |
| 107 | var b_in = b; | ||
| 108 | |||
| 109 | // Ascii short path. Only applies if they're the same length: | ||
| 110 | if (a_in.len == b_in.len) { | ||
| 111 | const prefix = ascii.caselessCmpLen(a_in, b_in); | ||
| 112 | if (prefix == a_in.len) return true; | ||
| 113 | a_in = a_in[prefix..]; | ||
| 114 | b_in = b_in[prefix..]; | ||
| 115 | } | ||
| 107 | 116 | ||
| 108 | // Process a | 117 | // Process a |
| 109 | const nfd_a = try Normalize.nfxdCodePoints(allocator, a, .nfd); | 118 | const nfd_a = try Normalize.nfxdCodePoints(allocator, a, .nfd); |
| @@ -192,10 +201,19 @@ pub fn canonCaselessMatch( | |||
| 192 | a: []const u8, | 201 | a: []const u8, |
| 193 | b: []const u8, | 202 | b: []const u8, |
| 194 | ) Allocator.Error!bool { | 203 | ) Allocator.Error!bool { |
| 195 | if (ascii.isAsciiOnly(a) and ascii.isAsciiOnly(b)) return std.ascii.eqlIgnoreCase(a, b); | 204 | var a_in = a; |
| 205 | var b_in = b; | ||
| 206 | |||
| 207 | // Ascii short path. Only applies if they're the same length: | ||
| 208 | if (a_in.len == b_in.len) { | ||
| 209 | const prefix = ascii.caselessCmpLen(a_in, b_in); | ||
| 210 | if (prefix == a_in.len) return true; | ||
| 211 | a_in = a_in[prefix..]; | ||
| 212 | b_in = b_in[prefix..]; | ||
| 213 | } | ||
| 196 | 214 | ||
| 197 | // Process a | 215 | // Process a |
| 198 | const nfd_a = try Normalize.nfxdCodePoints(allocator, a, .nfd); | 216 | const nfd_a = try Normalize.nfxdCodePoints(allocator, a_in, .nfd); |
| 199 | defer allocator.free(nfd_a); | 217 | defer allocator.free(nfd_a); |
| 200 | 218 | ||
| 201 | var need_free_cf_nfd_a = false; | 219 | var need_free_cf_nfd_a = false; |
| @@ -215,7 +233,7 @@ pub fn canonCaselessMatch( | |||
| 215 | defer if (need_free_nfd_cf_nfd_a) allocator.free(nfd_cf_nfd_a); | 233 | defer if (need_free_nfd_cf_nfd_a) allocator.free(nfd_cf_nfd_a); |
| 216 | 234 | ||
| 217 | // Process b | 235 | // Process b |
| 218 | const nfd_b = try Normalize.nfxdCodePoints(allocator, b, .nfd); | 236 | const nfd_b = try Normalize.nfxdCodePoints(allocator, b_in, .nfd); |
| 219 | defer allocator.free(nfd_b); | 237 | defer allocator.free(nfd_b); |
| 220 | 238 | ||
| 221 | var need_free_cf_nfd_b = false; | 239 | var need_free_cf_nfd_b = false; |