aboutsummaryrefslogtreecommitdiff
path: root/lib/std/mem.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-02-11 23:45:40 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-02-11 23:45:40 -0700
commitb4e344bcf859f2df89637e0825a2e0e57d092ef6 (patch)
tree44465c5c3eadcfdc57f0a0a3eb5cffff9107bd7f /lib/std/mem.zig
parent3d0f4b90305bc1815ccc86613cb3da715e9b62c0 (diff)
parentd3565ed6b48c9c66128f181e7b90b5348504cb3f (diff)
downloadzig-b4e344bcf859f2df89637e0825a2e0e57d092ef6.tar.gz
zig-b4e344bcf859f2df89637e0825a2e0e57d092ef6.zip
Merge remote-tracking branch 'origin/master' into ast-memory-layout
Conflicts: * lib/std/zig/ast.zig * lib/std/zig/parse.zig * lib/std/zig/parser_test.zig * lib/std/zig/render.zig * src/Module.zig * src/zir.zig I resolved some of the conflicts by reverting a small portion of @tadeokondrak's stage2 logic here regarding `callconv(.Inline)`. It will need to get reworked as part of this branch.
Diffstat (limited to 'lib/std/mem.zig')
-rw-r--r--lib/std/mem.zig13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/std/mem.zig b/lib/std/mem.zig
index 98a37e3d2b..5f23a10401 100644
--- a/lib/std/mem.zig
+++ b/lib/std/mem.zig
@@ -1507,7 +1507,7 @@ pub fn joinZ(allocator: *Allocator, separator: []const u8, slices: []const []con
}
fn joinMaybeZ(allocator: *Allocator, separator: []const u8, slices: []const []const u8, zero: bool) ![]u8 {
- if (slices.len == 0) return &[0]u8{};
+ if (slices.len == 0) return if (zero) try allocator.dupe(u8, &[1]u8{0}) else &[0]u8{};
const total_len = blk: {
var sum: usize = separator.len * (slices.len - 1);
@@ -1536,6 +1536,11 @@ fn joinMaybeZ(allocator: *Allocator, separator: []const u8, slices: []const []co
test "mem.join" {
{
+ const str = try join(testing.allocator, ",", &[_][]const u8{});
+ defer testing.allocator.free(str);
+ testing.expect(eql(u8, str, ""));
+ }
+ {
const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" });
defer testing.allocator.free(str);
testing.expect(eql(u8, str, "a,b,c"));
@@ -1554,6 +1559,12 @@ test "mem.join" {
test "mem.joinZ" {
{
+ const str = try joinZ(testing.allocator, ",", &[_][]const u8{});
+ defer testing.allocator.free(str);
+ testing.expect(eql(u8, str, ""));
+ testing.expectEqual(str[str.len], 0);
+ }
+ {
const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" });
defer testing.allocator.free(str);
testing.expect(eql(u8, str, "a,b,c"));