diff options
Diffstat (limited to 'src/Normalize.zig')
| -rw-r--r-- | src/Normalize.zig | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/src/Normalize.zig b/src/Normalize.zig index 6ef7c90..daf774d 100644 --- a/src/Normalize.zig +++ b/src/Normalize.zig | |||
| @@ -177,7 +177,7 @@ fn decompose( | |||
| 177 | 177 | ||
| 178 | test "decompose" { | 178 | test "decompose" { |
| 179 | const allocator = testing.allocator; | 179 | const allocator = testing.allocator; |
| 180 | var data = try NormData.init(allocator); | 180 | const data = try NormData.init(allocator); |
| 181 | defer data.deinit(); | 181 | defer data.deinit(); |
| 182 | var n = Self{ .norm_data = &data }; | 182 | var n = Self{ .norm_data = &data }; |
| 183 | 183 | ||
| @@ -225,7 +225,7 @@ pub const Result = struct { | |||
| 225 | allocator: ?mem.Allocator = null, | 225 | allocator: ?mem.Allocator = null, |
| 226 | slice: []const u8, | 226 | slice: []const u8, |
| 227 | 227 | ||
| 228 | pub fn deinit(self: *Result) void { | 228 | pub fn deinit(self: *const Result) void { |
| 229 | if (self.allocator) |allocator| allocator.free(self.slice); | 229 | if (self.allocator) |allocator| allocator.free(self.slice); |
| 230 | } | 230 | } |
| 231 | }; | 231 | }; |
| @@ -297,11 +297,11 @@ fn nfxd(self: Self, allocator: mem.Allocator, str: []const u8, form: Form) !Resu | |||
| 297 | 297 | ||
| 298 | test "nfd ASCII / no-alloc" { | 298 | test "nfd ASCII / no-alloc" { |
| 299 | const allocator = testing.allocator; | 299 | const allocator = testing.allocator; |
| 300 | var data = try NormData.init(allocator); | 300 | const data = try NormData.init(allocator); |
| 301 | defer data.deinit(); | 301 | defer data.deinit(); |
| 302 | var n = Self{ .norm_data = &data }; | 302 | const n = Self{ .norm_data = &data }; |
| 303 | 303 | ||
| 304 | var result = try n.nfd(allocator, "Hello World!"); | 304 | const result = try n.nfd(allocator, "Hello World!"); |
| 305 | defer result.deinit(); | 305 | defer result.deinit(); |
| 306 | 306 | ||
| 307 | try testing.expectEqualStrings("Hello World!", result.slice); | 307 | try testing.expectEqualStrings("Hello World!", result.slice); |
| @@ -309,11 +309,11 @@ test "nfd ASCII / no-alloc" { | |||
| 309 | 309 | ||
| 310 | test "nfd !ASCII / alloc" { | 310 | test "nfd !ASCII / alloc" { |
| 311 | const allocator = testing.allocator; | 311 | const allocator = testing.allocator; |
| 312 | var data = try NormData.init(allocator); | 312 | const data = try NormData.init(allocator); |
| 313 | defer data.deinit(); | 313 | defer data.deinit(); |
| 314 | var n = Self{ .norm_data = &data }; | 314 | const n = Self{ .norm_data = &data }; |
| 315 | 315 | ||
| 316 | var result = try n.nfd(allocator, "Héllo World! \u{3d3}"); | 316 | const result = try n.nfd(allocator, "Héllo World! \u{3d3}"); |
| 317 | defer result.deinit(); | 317 | defer result.deinit(); |
| 318 | 318 | ||
| 319 | try testing.expectEqualStrings("He\u{301}llo World! \u{3d2}\u{301}", result.slice); | 319 | try testing.expectEqualStrings("He\u{301}llo World! \u{3d2}\u{301}", result.slice); |
| @@ -321,11 +321,11 @@ test "nfd !ASCII / alloc" { | |||
| 321 | 321 | ||
| 322 | test "nfkd ASCII / no-alloc" { | 322 | test "nfkd ASCII / no-alloc" { |
| 323 | const allocator = testing.allocator; | 323 | const allocator = testing.allocator; |
| 324 | var data = try NormData.init(allocator); | 324 | const data = try NormData.init(allocator); |
| 325 | defer data.deinit(); | 325 | defer data.deinit(); |
| 326 | var n = Self{ .norm_data = &data }; | 326 | const n = Self{ .norm_data = &data }; |
| 327 | 327 | ||
| 328 | var result = try n.nfkd(allocator, "Hello World!"); | 328 | const result = try n.nfkd(allocator, "Hello World!"); |
| 329 | defer result.deinit(); | 329 | defer result.deinit(); |
| 330 | 330 | ||
| 331 | try testing.expectEqualStrings("Hello World!", result.slice); | 331 | try testing.expectEqualStrings("Hello World!", result.slice); |
| @@ -333,11 +333,11 @@ test "nfkd ASCII / no-alloc" { | |||
| 333 | 333 | ||
| 334 | test "nfkd !ASCII / alloc" { | 334 | test "nfkd !ASCII / alloc" { |
| 335 | const allocator = testing.allocator; | 335 | const allocator = testing.allocator; |
| 336 | var data = try NormData.init(allocator); | 336 | const data = try NormData.init(allocator); |
| 337 | defer data.deinit(); | 337 | defer data.deinit(); |
| 338 | var n = Self{ .norm_data = &data }; | 338 | const n = Self{ .norm_data = &data }; |
| 339 | 339 | ||
| 340 | var result = try n.nfkd(allocator, "Héllo World! \u{3d3}"); | 340 | const result = try n.nfkd(allocator, "Héllo World! \u{3d3}"); |
| 341 | defer result.deinit(); | 341 | defer result.deinit(); |
| 342 | 342 | ||
| 343 | try testing.expectEqualStrings("He\u{301}llo World! \u{3a5}\u{301}", result.slice); | 343 | try testing.expectEqualStrings("He\u{301}llo World! \u{3a5}\u{301}", result.slice); |
| @@ -532,11 +532,11 @@ fn nfxc(self: Self, allocator: mem.Allocator, str: []const u8, form: Form) !Resu | |||
| 532 | 532 | ||
| 533 | test "nfc" { | 533 | test "nfc" { |
| 534 | const allocator = testing.allocator; | 534 | const allocator = testing.allocator; |
| 535 | var data = try NormData.init(allocator); | 535 | const data = try NormData.init(allocator); |
| 536 | defer data.deinit(); | 536 | defer data.deinit(); |
| 537 | var n = Self{ .norm_data = &data }; | 537 | const n = Self{ .norm_data = &data }; |
| 538 | 538 | ||
| 539 | var result = try n.nfc(allocator, "Complex char: \u{3D2}\u{301}"); | 539 | const result = try n.nfc(allocator, "Complex char: \u{3D2}\u{301}"); |
| 540 | defer result.deinit(); | 540 | defer result.deinit(); |
| 541 | 541 | ||
| 542 | try testing.expectEqualStrings("Complex char: \u{3D3}", result.slice); | 542 | try testing.expectEqualStrings("Complex char: \u{3D3}", result.slice); |
| @@ -544,11 +544,11 @@ test "nfc" { | |||
| 544 | 544 | ||
| 545 | test "nfkc" { | 545 | test "nfkc" { |
| 546 | const allocator = testing.allocator; | 546 | const allocator = testing.allocator; |
| 547 | var data = try NormData.init(allocator); | 547 | const data = try NormData.init(allocator); |
| 548 | defer data.deinit(); | 548 | defer data.deinit(); |
| 549 | var n = Self{ .norm_data = &data }; | 549 | const n = Self{ .norm_data = &data }; |
| 550 | 550 | ||
| 551 | var result = try n.nfkc(allocator, "Complex char: \u{03A5}\u{0301}"); | 551 | const result = try n.nfkc(allocator, "Complex char: \u{03A5}\u{0301}"); |
| 552 | defer result.deinit(); | 552 | defer result.deinit(); |
| 553 | 553 | ||
| 554 | try testing.expectEqualStrings("Complex char: \u{038E}", result.slice); | 554 | try testing.expectEqualStrings("Complex char: \u{038E}", result.slice); |
| @@ -556,9 +556,9 @@ test "nfkc" { | |||
| 556 | 556 | ||
| 557 | /// Tests for equality of `a` and `b` after normalizing to NFC. | 557 | /// Tests for equality of `a` and `b` after normalizing to NFC. |
| 558 | pub fn eql(self: Self, allocator: mem.Allocator, a: []const u8, b: []const u8) !bool { | 558 | pub fn eql(self: Self, allocator: mem.Allocator, a: []const u8, b: []const u8) !bool { |
| 559 | var norm_result_a = try self.nfc(allocator, a); | 559 | const norm_result_a = try self.nfc(allocator, a); |
| 560 | defer norm_result_a.deinit(); | 560 | defer norm_result_a.deinit(); |
| 561 | var norm_result_b = try self.nfc(allocator, b); | 561 | const norm_result_b = try self.nfc(allocator, b); |
| 562 | defer norm_result_b.deinit(); | 562 | defer norm_result_b.deinit(); |
| 563 | 563 | ||
| 564 | return mem.eql(u8, norm_result_a.slice, norm_result_b.slice); | 564 | return mem.eql(u8, norm_result_a.slice, norm_result_b.slice); |
| @@ -566,9 +566,9 @@ pub fn eql(self: Self, allocator: mem.Allocator, a: []const u8, b: []const u8) ! | |||
| 566 | 566 | ||
| 567 | test "eql" { | 567 | test "eql" { |
| 568 | const allocator = testing.allocator; | 568 | const allocator = testing.allocator; |
| 569 | var data = try NormData.init(allocator); | 569 | const data = try NormData.init(allocator); |
| 570 | defer data.deinit(); | 570 | defer data.deinit(); |
| 571 | var n = Self{ .norm_data = &data }; | 571 | const n = Self{ .norm_data = &data }; |
| 572 | 572 | ||
| 573 | try testing.expect(try n.eql(allocator, "foé", "foe\u{0301}")); | 573 | try testing.expect(try n.eql(allocator, "foé", "foe\u{0301}")); |
| 574 | try testing.expect(try n.eql(allocator, "foϓ", "fo\u{03D2}\u{0301}")); | 574 | try testing.expect(try n.eql(allocator, "foϓ", "fo\u{03D2}\u{0301}")); |
| @@ -601,9 +601,9 @@ fn isFcd(self: Self, str: []const u8) bool { | |||
| 601 | 601 | ||
| 602 | test "isFcd" { | 602 | test "isFcd" { |
| 603 | const allocator = testing.allocator; | 603 | const allocator = testing.allocator; |
| 604 | var data = try NormData.init(allocator); | 604 | const data = try NormData.init(allocator); |
| 605 | defer data.deinit(); | 605 | defer data.deinit(); |
| 606 | var n = Self{ .norm_data = &data }; | 606 | const n = Self{ .norm_data = &data }; |
| 607 | 607 | ||
| 608 | const is_nfc = "José \u{3D3}"; | 608 | const is_nfc = "José \u{3D3}"; |
| 609 | try testing.expect(n.isFcd(is_nfc)); | 609 | try testing.expect(n.isFcd(is_nfc)); |
| @@ -620,9 +620,9 @@ test "Unicode normalization tests" { | |||
| 620 | defer arena.deinit(); | 620 | defer arena.deinit(); |
| 621 | var allocator = arena.allocator(); | 621 | var allocator = arena.allocator(); |
| 622 | 622 | ||
| 623 | var data = try NormData.init(allocator); | 623 | const data = try NormData.init(allocator); |
| 624 | defer data.deinit(); | 624 | defer data.deinit(); |
| 625 | var n = Self{ .norm_data = &data }; | 625 | const n = Self{ .norm_data = &data }; |
| 626 | 626 | ||
| 627 | var file = try fs.cwd().openFile("data/unicode/NormalizationTest.txt", .{}); | 627 | var file = try fs.cwd().openFile("data/unicode/NormalizationTest.txt", .{}); |
| 628 | defer file.close(); | 628 | defer file.close(); |
| @@ -721,7 +721,7 @@ test "Unicode normalization tests" { | |||
| 721 | } | 721 | } |
| 722 | 722 | ||
| 723 | const want = w_buf.items; | 723 | const want = w_buf.items; |
| 724 | var got = try n.nfkd(allocator, input); | 724 | const got = try n.nfkd(allocator, input); |
| 725 | defer got.deinit(); | 725 | defer got.deinit(); |
| 726 | 726 | ||
| 727 | try testing.expectEqualStrings(want, got.slice); | 727 | try testing.expectEqualStrings(want, got.slice); |