Skip to content

Instantly share code, notes, and snippets.

@lithdew
Created July 29, 2020 00:58
Show Gist options
  • Save lithdew/7ce0dd2d344516dccf600a1f4ff2dbad to your computer and use it in GitHub Desktop.
Save lithdew/7ce0dd2d344516dccf600a1f4ff2dbad to your computer and use it in GitHub Desktop.
zig concat
const std = @import("std");
pub fn concat(bufs: []const []const u8) ![]const u8 {
// var buf: [11]u8 = undefined;
// var buffer = std.heap.FixedBufferAllocator.init(&buf);
return std.mem.concat(std.heap.c_allocator, u8, bufs);
// return std.mem.concat(&buffer.allocator, u8, bufs);
}
pub fn main() !void {
var first = try concat(&[_][]const u8{ "hello ", "world" });
defer std.heap.c_allocator.free(first);
std.debug.print("{}\n", .{first});
var sec = try concat(&[_][]const u8{ "test ", "two" });
defer std.heap.c_allocator.free(sec);
std.debug.print("{} {}\n", .{ first, sec });
var thir = try concat(&[_][]const u8{ "xxxx ", "yyyyy" });
defer std.heap.c_allocator.free(thir);
std.debug.print("{} {} {}\n", .{ first, sec, thir });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment