Function join [src]

Naively combines a series of paths with the native path separator. Allocates memory for the result, which must be freed by the caller.

Prototype

pub fn join(allocator: Allocator, paths: []const []const u8) ![]u8

Parameters

allocator: Allocatorpaths: []const []const u8

Example

test join { { const actual: []u8 = try join(testing.allocator, &[_][]const u8{}); defer testing.allocator.free(actual); try testing.expectEqualSlices(u8, "", actual); } { const actual: [:0]u8 = try joinZ(testing.allocator, &[_][]const u8{}); defer testing.allocator.free(actual); try testing.expectEqualSlices(u8, "", actual); } for (&[_]bool{ false, true }) |zero| { try testJoinMaybeZWindows(&[_][]const u8{}, "", zero); try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero); try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero); try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c", zero); try testJoinMaybeZWindows(&[_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c", zero); try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c", zero); try testJoinMaybeZWindows( &[_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" }, "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig", zero, ); try testJoinMaybeZUefi(&[_][]const u8{ "EFI", "Boot", "bootx64.efi" }, "EFI\\Boot\\bootx64.efi", zero); try testJoinMaybeZUefi(&[_][]const u8{ "EFI\\Boot", "bootx64.efi" }, "EFI\\Boot\\bootx64.efi", zero); try testJoinMaybeZUefi(&[_][]const u8{ "EFI\\", "\\Boot", "bootx64.efi" }, "EFI\\Boot\\bootx64.efi", zero); try testJoinMaybeZUefi(&[_][]const u8{ "EFI\\", "\\Boot\\", "\\bootx64.efi" }, "EFI\\Boot\\bootx64.efi", zero); try testJoinMaybeZWindows(&[_][]const u8{ "c:\\", "a", "b/", "c" }, "c:\\a\\b/c", zero); try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a/", "b\\", "/c" }, "c:\\a/b\\c", zero); try testJoinMaybeZWindows(&[_][]const u8{ "", "c:\\", "", "", "a", "b\\", "c", "" }, "c:\\a\\b\\c", zero); try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a/", "", "b\\", "", "/c" }, "c:\\a/b\\c", zero); try testJoinMaybeZWindows(&[_][]const u8{ "", "" }, "", zero); try testJoinMaybeZPosix(&[_][]const u8{}, "", zero); try testJoinMaybeZPosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c", zero); try testJoinMaybeZPosix(&[_][]const u8{ "/a/b/", "c" }, "/a/b/c", zero); try testJoinMaybeZPosix(&[_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c", zero); try testJoinMaybeZPosix(&[_][]const u8{ "/a/", "b/", "c" }, "/a/b/c", zero); try testJoinMaybeZPosix( &[_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" }, "/home/andy/dev/zig/build/lib/zig/std/io.zig", zero, ); try testJoinMaybeZPosix(&[_][]const u8{ "a", "/c" }, "a/c", zero); try testJoinMaybeZPosix(&[_][]const u8{ "a/", "/c" }, "a/c", zero); try testJoinMaybeZPosix(&[_][]const u8{ "", "/", "a", "", "b/", "c", "" }, "/a/b/c", zero); try testJoinMaybeZPosix(&[_][]const u8{ "/a/", "", "", "b/", "c" }, "/a/b/c", zero); try testJoinMaybeZPosix(&[_][]const u8{ "", "" }, "", zero); } }

Source

pub fn join(allocator: Allocator, paths: []const []const u8) ![]u8 { return joinSepMaybeZ(allocator, sep, isSep, paths, false); }