| ... | @@ -1507,7 +1507,7 @@ pub fn joinZ(allocator: *Allocator, separator: []const u8, slices: []const []con | ... | @@ -1507,7 +1507,7 @@ pub fn joinZ(allocator: *Allocator, separator: []const u8, slices: []const []con |
| 1507 | } | 1507 | } |
| 1508 | | 1508 | |
| 1509 | fn joinMaybeZ(allocator: *Allocator, separator: []const u8, slices: []const []const u8, zero: bool) ![]u8 { | 1509 | fn joinMaybeZ(allocator: *Allocator, separator: []const u8, slices: []const []const u8, zero: bool) ![]u8 { |
| 1510 | if (slices.len == 0) return &[0]u8{}; | 1510 | if (slices.len == 0) return if (zero) try allocator.dupe(u8, &[1]u8{0}) else &[0]u8{}; |
| 1511 | | 1511 | |
| 1512 | const total_len = blk: { | 1512 | const total_len = blk: { |
| 1513 | var sum: usize = separator.len * (slices.len - 1); | 1513 | var sum: usize = separator.len * (slices.len - 1); |
| ... | @@ -1535,6 +1535,11 @@ fn joinMaybeZ(allocator: *Allocator, separator: []const u8, slices: []const []co | ... | @@ -1535,6 +1535,11 @@ fn joinMaybeZ(allocator: *Allocator, separator: []const u8, slices: []const []co |
| 1535 | } | 1535 | } |
| 1536 | | 1536 | |
| 1537 | test "mem.join" { | 1537 | test "mem.join" { |
| | 1538 | { |
| | 1539 | const str = try join(testing.allocator, ",", &[_][]const u8{}); |
| | 1540 | defer testing.allocator.free(str); |
| | 1541 | testing.expect(eql(u8, str, "")); |
| | 1542 | } |
| 1538 | { | 1543 | { |
| 1539 | const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" }); | 1544 | const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" }); |
| 1540 | defer testing.allocator.free(str); | 1545 | defer testing.allocator.free(str); |
| ... | @@ -1553,6 +1558,12 @@ test "mem.join" { | ... | @@ -1553,6 +1558,12 @@ test "mem.join" { |
| 1553 | } | 1558 | } |
| 1554 | | 1559 | |
| 1555 | test "mem.joinZ" { | 1560 | test "mem.joinZ" { |
| | 1561 | { |
| | 1562 | const str = try joinZ(testing.allocator, ",", &[_][]const u8{}); |
| | 1563 | defer testing.allocator.free(str); |
| | 1564 | testing.expect(eql(u8, str, "")); |
| | 1565 | testing.expectEqual(str[str.len], 0); |
| | 1566 | } |
| 1556 | { | 1567 | { |
| 1557 | const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" }); | 1568 | const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" }); |
| 1558 | defer testing.allocator.free(str); | 1569 | defer testing.allocator.free(str); |