diff options
| author | Andrea Orru <andreaorru1991@gmail.com> | 2017-05-28 15:54:53 +0200 |
|---|---|---|
| committer | Andrea Orru <andreaorru1991@gmail.com> | 2017-05-28 15:54:53 +0200 |
| commit | 6a87aa4d2ee6af624d817ebfdf6e39ff77019a9f (patch) | |
| tree | fcff295ff06794097bab49d7f0cd3caef76fad5c /std/os | |
| parent | 2dfb1ebee2bc215271e5416b723d746af319621b (diff) | |
| download | zig-6a87aa4d2ee6af624d817ebfdf6e39ff77019a9f.tar.gz zig-6a87aa4d2ee6af624d817ebfdf6e39ff77019a9f.zip | |
Generalize join.
Diffstat (limited to 'std/os')
| -rw-r--r-- | std/os/path.zig | 29 |
1 files changed, 1 insertions, 28 deletions
diff --git a/std/os/path.zig b/std/os/path.zig index ce767f6bae..5477d44420 100644 --- a/std/os/path.zig +++ b/std/os/path.zig @@ -21,34 +21,7 @@ pub const delimiter = switch (builtin.os) { /// Naively combines a series of paths with the native path seperator. /// Allocates memory for the result, which must be freed by the caller. pub fn join(allocator: &Allocator, paths: ...) -> %[]u8 { - comptime assert(paths.len >= 2); - var total_paths_len: usize = paths.len; // 1 slash per path - { - comptime var path_i = 0; - inline while (path_i < paths.len) : (path_i += 1) { - const arg = ([]const u8)(paths[path_i]); - total_paths_len += arg.len; - } - } - - const buf = %return allocator.alloc(u8, total_paths_len); - %defer allocator.free(buf); - - var buf_index: usize = 0; - comptime var path_i = 0; - inline while (true) { - const arg = ([]const u8)(paths[path_i]); - path_i += 1; - mem.copy(u8, buf[buf_index..], arg); - buf_index += arg.len; - if (path_i >= paths.len) break; - if (buf[buf_index - 1] != sep) { - buf[buf_index] = sep; - buf_index += 1; - } - } - - return buf[0..buf_index]; + mem.join(allocator, sep, paths) } test "os.path.join" { |
