summaryrefslogtreecommitdiff
path: root/src/Normalize.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Normalize.zig')
-rw-r--r--src/Normalize.zig22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/Normalize.zig b/src/Normalize.zig
index f2dbb3e..1e9878b 100644
--- a/src/Normalize.zig
+++ b/src/Normalize.zig
@@ -245,16 +245,16 @@ fn canonicalSort(self: Self, cps: []u21) void {
245} 245}
246 246
247/// Normalize `str` to NFD. 247/// Normalize `str` to NFD.
248pub fn nfd(self: Self, allocator: mem.Allocator, str: []const u8) !Result { 248pub fn nfd(self: Self, allocator: mem.Allocator, str: []const u8) mem.Allocator.Error!Result {
249 return self.nfxd(allocator, str, .nfd); 249 return self.nfxd(allocator, str, .nfd);
250} 250}
251 251
252/// Normalize `str` to NFKD. 252/// Normalize `str` to NFKD.
253pub fn nfkd(self: Self, allocator: mem.Allocator, str: []const u8) !Result { 253pub fn nfkd(self: Self, allocator: mem.Allocator, str: []const u8) mem.Allocator.Error!Result {
254 return self.nfxd(allocator, str, .nfkd); 254 return self.nfxd(allocator, str, .nfkd);
255} 255}
256 256
257pub fn nfxdCodePoints(self: Self, allocator: mem.Allocator, str: []const u8, form: Form) ![]u21 { 257pub fn nfxdCodePoints(self: Self, allocator: mem.Allocator, str: []const u8, form: Form) mem.Allocator.Error![]u21 {
258 var dcp_list = std.ArrayList(u21).init(allocator); 258 var dcp_list = std.ArrayList(u21).init(allocator);
259 defer dcp_list.deinit(); 259 defer dcp_list.deinit();
260 260
@@ -275,7 +275,7 @@ pub fn nfxdCodePoints(self: Self, allocator: mem.Allocator, str: []const u8, for
275 return try dcp_list.toOwnedSlice(); 275 return try dcp_list.toOwnedSlice();
276} 276}
277 277
278fn nfxd(self: Self, allocator: mem.Allocator, str: []const u8, form: Form) !Result { 278fn nfxd(self: Self, allocator: mem.Allocator, str: []const u8, form: Form) mem.Allocator.Error!Result {
279 // Quick checks. 279 // Quick checks.
280 if (ascii.isAsciiOnly(str)) return Result{ .slice = str }; 280 if (ascii.isAsciiOnly(str)) return Result{ .slice = str };
281 281
@@ -287,7 +287,7 @@ fn nfxd(self: Self, allocator: mem.Allocator, str: []const u8, form: Form) !Resu
287 var buf: [4]u8 = undefined; 287 var buf: [4]u8 = undefined;
288 288
289 for (dcps) |dcp| { 289 for (dcps) |dcp| {
290 const len = try unicode.utf8Encode(dcp, &buf); 290 const len = unicode.utf8Encode(dcp, &buf) catch unreachable;
291 try dstr_list.appendSlice(buf[0..len]); 291 try dstr_list.appendSlice(buf[0..len]);
292 } 292 }
293 293
@@ -350,7 +350,7 @@ pub fn nfdCodePoints(
350 self: Self, 350 self: Self,
351 allocator: mem.Allocator, 351 allocator: mem.Allocator,
352 cps: []const u21, 352 cps: []const u21,
353) ![]u21 { 353) mem.Allocator.Error![]u21 {
354 var dcp_list = std.ArrayList(u21).init(allocator); 354 var dcp_list = std.ArrayList(u21).init(allocator);
355 defer dcp_list.deinit(); 355 defer dcp_list.deinit();
356 356
@@ -375,7 +375,7 @@ pub fn nfkdCodePoints(
375 self: Self, 375 self: Self,
376 allocator: mem.Allocator, 376 allocator: mem.Allocator,
377 cps: []const u21, 377 cps: []const u21,
378) ![]u21 { 378) mem.Allocator.Error![]u21 {
379 var dcp_list = std.ArrayList(u21).init(allocator); 379 var dcp_list = std.ArrayList(u21).init(allocator);
380 defer dcp_list.deinit(); 380 defer dcp_list.deinit();
381 381
@@ -403,16 +403,16 @@ fn isHangul(self: Self, cp: u21) bool {
403} 403}
404 404
405/// Normalizes `str` to NFC. 405/// Normalizes `str` to NFC.
406pub fn nfc(self: Self, allocator: mem.Allocator, str: []const u8) !Result { 406pub fn nfc(self: Self, allocator: mem.Allocator, str: []const u8) mem.Allocator.Error!Result {
407 return self.nfxc(allocator, str, .nfc); 407 return self.nfxc(allocator, str, .nfc);
408} 408}
409 409
410/// Normalizes `str` to NFKC. 410/// Normalizes `str` to NFKC.
411pub fn nfkc(self: Self, allocator: mem.Allocator, str: []const u8) !Result { 411pub fn nfkc(self: Self, allocator: mem.Allocator, str: []const u8) mem.Allocator.Error!Result {
412 return self.nfxc(allocator, str, .nfkc); 412 return self.nfxc(allocator, str, .nfkc);
413} 413}
414 414
415fn nfxc(self: Self, allocator: mem.Allocator, str: []const u8, form: Form) !Result { 415fn nfxc(self: Self, allocator: mem.Allocator, str: []const u8, form: Form) mem.Allocator.Error!Result {
416 // Quick checks. 416 // Quick checks.
417 if (ascii.isAsciiOnly(str)) return Result{ .slice = str }; 417 if (ascii.isAsciiOnly(str)) return Result{ .slice = str };
418 if (form == .nfc and isLatin1Only(str)) return Result{ .slice = str }; 418 if (form == .nfc and isLatin1Only(str)) return Result{ .slice = str };
@@ -524,7 +524,7 @@ fn nfxc(self: Self, allocator: mem.Allocator, str: []const u8, form: Form) !Resu
524 524
525 for (dcps) |cp| { 525 for (dcps) |cp| {
526 if (cp == tombstone) continue; // "Delete" 526 if (cp == tombstone) continue; // "Delete"
527 const len = try unicode.utf8Encode(cp, &buf); 527 const len = unicode.utf8Encode(cp, &buf) catch unreachable;
528 try cstr_list.appendSlice(buf[0..len]); 528 try cstr_list.appendSlice(buf[0..len]);
529 } 529 }
530 530