authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-04 15:24:06-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-04 15:24:06-05:00
log67bd45f0cf1b452cf8de5a016bc6ff2f85393d70
tree2c3da09e586d0fd21f81bbe66148db490e23762f
parentf44ce7836a2f1d29e4f4718d45d6dca3c44ed919
signaturelock-open Commit is signed but in an unrecognized format.

adjustments to std.mem split / separate

* rename std.mem.split to std.mem.tokenize * add future deprecation notice to docs * (unrelated) add note to std.os.path.resolve docs * std.mem.separate - assert delimiter.len not zero * fix implementation of std.mem.separate to respect the delimiter * separate the two iterators to different structs

8 files changed, 112 insertions(+), 97 deletions(-)

build.zig+8-8
......@@ -189,14 +189,14 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
189189 const prefix_output = try b.exec([][]const u8{ llvm_config_exe, "--prefix" });
190190
191191 var result = LibraryDep{
192 .prefix = mem.split(prefix_output, " \r\n").next().?,
192 .prefix = mem.tokenize(prefix_output, " \r\n").next().?,
193193 .libs = ArrayList([]const u8).init(b.allocator),
194194 .system_libs = ArrayList([]const u8).init(b.allocator),
195195 .includes = ArrayList([]const u8).init(b.allocator),
196196 .libdirs = ArrayList([]const u8).init(b.allocator),
197197 };
198198 {
199 var it = mem.split(libs_output, " \r\n");
199 var it = mem.tokenize(libs_output, " \r\n");
200200 while (it.next()) |lib_arg| {
201201 if (mem.startsWith(u8, lib_arg, "-l")) {
202202 try result.system_libs.append(lib_arg[2..]);
......@@ -210,7 +210,7 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
210210 }
211211 }
212212 {
213 var it = mem.split(includes_output, " \r\n");
213 var it = mem.tokenize(includes_output, " \r\n");
214214 while (it.next()) |include_arg| {
215215 if (mem.startsWith(u8, include_arg, "-I")) {
216216 try result.includes.append(include_arg[2..]);
......@@ -220,7 +220,7 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
220220 }
221221 }
222222 {
223 var it = mem.split(libdir_output, " \r\n");
223 var it = mem.tokenize(libdir_output, " \r\n");
224224 while (it.next()) |libdir| {
225225 if (mem.startsWith(u8, libdir, "-L")) {
226226 try result.libdirs.append(libdir[2..]);
......@@ -233,7 +233,7 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
233233}
234234
235235pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {
236 var it = mem.split(stdlib_files, ";");
236 var it = mem.tokenize(stdlib_files, ";");
237237 while (it.next()) |stdlib_file| {
238238 const src_path = os.path.join(b.allocator, "std", stdlib_file) catch unreachable;
239239 const dest_path = os.path.join(b.allocator, "lib", "zig", "std", stdlib_file) catch unreachable;
......@@ -242,7 +242,7 @@ pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {
242242}
243243
244244pub fn installCHeaders(b: *Builder, c_header_files: []const u8) void {
245 var it = mem.split(c_header_files, ";");
245 var it = mem.tokenize(c_header_files, ";");
246246 while (it.next()) |c_header_file| {
247247 const src_path = os.path.join(b.allocator, "c_headers", c_header_file) catch unreachable;
248248 const dest_path = os.path.join(b.allocator, "lib", "zig", "include", c_header_file) catch unreachable;
......@@ -277,7 +277,7 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void {
277277 addCppLib(b, exe, ctx.cmake_binary_dir, "zig_cpp");
278278 if (ctx.lld_include_dir.len != 0) {
279279 exe.addIncludeDir(ctx.lld_include_dir);
280 var it = mem.split(ctx.lld_libraries, ";");
280 var it = mem.tokenize(ctx.lld_libraries, ";");
281281 while (it.next()) |lib| {
282282 exe.addObjectFile(lib);
283283 }
......@@ -334,7 +334,7 @@ fn addCxxKnownPath(
334334 ctx.cxx_compiler,
335335 b.fmt("-print-file-name={}", objname),
336336 });
337 const path_unpadded = mem.split(path_padded, "\r\n").next().?;
337 const path_unpadded = mem.tokenize(path_padded, "\r\n").next().?;
338338 if (mem.eql(u8, path_unpadded, objname)) {
339339 if (errtxt) |msg| {
340340 warn("{}", msg);
src-self-hosted/libc_installation.zig+4-4
......@@ -57,10 +57,10 @@ pub const LibCInstallation = struct {
5757 const contents = try std.io.readFileAlloc(allocator, libc_file);
5858 defer allocator.free(contents);
5959
60 var it = std.mem.split(contents, "\n");
60 var it = std.mem.tokenize(contents, "\n");
6161 while (it.next()) |line| {
6262 if (line.len == 0 or line[0] == '#') continue;
63 var line_it = std.mem.split(line, "=");
63 var line_it = std.mem.separate(line, "=");
6464 const name = line_it.next() orelse {
6565 try stderr.print("missing equal sign after field name\n");
6666 return error.ParseError;
......@@ -213,7 +213,7 @@ pub const LibCInstallation = struct {
213213 },
214214 }
215215
216 var it = std.mem.split(exec_result.stderr, "\n\r");
216 var it = std.mem.tokenize(exec_result.stderr, "\n\r");
217217 var search_paths = std.ArrayList([]const u8).init(loop.allocator);
218218 defer search_paths.deinit();
219219 while (it.next()) |line| {
......@@ -410,7 +410,7 @@ async fn ccPrintFileName(loop: *event.Loop, o_file: []const u8, want_dirname: bo
410410 return error.CCompilerCrashed;
411411 },
412412 }
413 var it = std.mem.split(exec_result.stdout, "\n\r");
413 var it = std.mem.tokenize(exec_result.stdout, "\n\r");
414414 const line = it.next() orelse return error.LibCRuntimeNotFound;
415415 const dirname = std.os.path.dirname(line) orelse return error.LibCRuntimeNotFound;
416416
src-self-hosted/main.zig+1-1
......@@ -351,7 +351,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
351351 const root_name = if (provided_name) |n| n else blk: {
352352 if (root_source_file) |file| {
353353 const basename = os.path.basename(file);
354 var it = mem.split(basename, ".");
354 var it = mem.separate(basename, ".");
355355 break :blk it.next() orelse basename;
356356 } else {
357357 try stderr.write("--name [name] not provided and unable to infer\n");
std/build.zig+3-3
......@@ -324,7 +324,7 @@ pub const Builder = struct {
324324
325325 fn processNixOSEnvVars(self: *Builder) void {
326326 if (os.getEnvVarOwned(self.allocator, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {
327 var it = mem.split(nix_cflags_compile, " ");
327 var it = mem.tokenize(nix_cflags_compile, " ");
328328 while (true) {
329329 const word = it.next() orelse break;
330330 if (mem.eql(u8, word, "-isystem")) {
......@@ -342,7 +342,7 @@ pub const Builder = struct {
342342 assert(err == error.EnvironmentVariableNotFound);
343343 }
344344 if (os.getEnvVarOwned(self.allocator, "NIX_LDFLAGS")) |nix_ldflags| {
345 var it = mem.split(nix_ldflags, " ");
345 var it = mem.tokenize(nix_ldflags, " ");
346346 while (true) {
347347 const word = it.next() orelse break;
348348 if (mem.eql(u8, word, "-rpath")) {
......@@ -689,7 +689,7 @@ pub const Builder = struct {
689689 if (os.path.isAbsolute(name)) {
690690 return name;
691691 }
692 var it = mem.split(PATH, []u8{os.path.delimiter});
692 var it = mem.tokenize(PATH, []u8{os.path.delimiter});
693693 while (it.next()) |path| {
694694 const full_path = try os.path.join(self.allocator, path, self.fmt("{}{}", name, exe_extension));
695695 if (os.path.real(self.allocator, full_path)) |real_path| {
std/mem.zig+71-58
......@@ -689,58 +689,57 @@ pub fn eql_slice_u8(a: []const u8, b: []const u8) bool {
689689}
690690
691691/// Returns an iterator that iterates over the slices of `buffer` that are not
692/// any of the bytes in `split_bytes`.
693/// split(" abc def ghi ", " ")
692/// any of the bytes in `delimiter_bytes`.
693/// tokenize(" abc def ghi ", " ")
694694/// Will return slices for "abc", "def", "ghi", null, in that order.
695/// If `split_bytes` does not exist in buffer,
695/// If `buffer` is empty, the iterator will return null.
696/// If `delimiter_bytes` does not exist in buffer,
696697/// the iterator will return `buffer`, null, in that order.
697pub fn split(buffer: []const u8, split_bytes: []const u8) SplitIterator {
698 return SplitIterator{
698/// See also the related function `separate`.
699pub fn tokenize(buffer: []const u8, delimiter_bytes: []const u8) TokenIterator {
700 return TokenIterator{
699701 .index = 0,
700702 .buffer = buffer,
701 .split_bytes = split_bytes,
702 .glob = true,
703 .spun = false,
703 .delimiter_bytes = delimiter_bytes,
704704 };
705705}
706706
707test "mem.split" {
708 var it = split(" abc def ghi ", " ");
707test "mem.tokenize" {
708 var it = tokenize(" abc def ghi ", " ");
709709 assert(eql(u8, it.next().?, "abc"));
710710 assert(eql(u8, it.next().?, "def"));
711711 assert(eql(u8, it.next().?, "ghi"));
712712 assert(it.next() == null);
713713
714 it = split("..\\bob", "\\");
714 it = tokenize("..\\bob", "\\");
715715 assert(eql(u8, it.next().?, ".."));
716716 assert(eql(u8, "..", "..\\bob"[0..it.index]));
717717 assert(eql(u8, it.next().?, "bob"));
718718 assert(it.next() == null);
719719
720 it = split("//a/b", "/");
720 it = tokenize("//a/b", "/");
721721 assert(eql(u8, it.next().?, "a"));
722722 assert(eql(u8, it.next().?, "b"));
723723 assert(eql(u8, "//a/b", "//a/b"[0..it.index]));
724724 assert(it.next() == null);
725725
726 it = split("|", "|");
726 it = tokenize("|", "|");
727727 assert(it.next() == null);
728728
729 it = split("", "|");
730 assert(eql(u8, it.next().?, ""));
729 it = tokenize("", "|");
731730 assert(it.next() == null);
732731
733 it = split("hello", "");
732 it = tokenize("hello", "");
734733 assert(eql(u8, it.next().?, "hello"));
735734 assert(it.next() == null);
736735
737 it = split("hello", " ");
736 it = tokenize("hello", " ");
738737 assert(eql(u8, it.next().?, "hello"));
739738 assert(it.next() == null);
740739}
741740
742test "mem.split (multibyte)" {
743 var it = split("a|b,c/d e", " /,|");
741test "mem.tokenize (multibyte)" {
742 var it = tokenize("a|b,c/d e", " /,|");
744743 assert(eql(u8, it.next().?, "a"));
745744 assert(eql(u8, it.next().?, "b"));
746745 assert(eql(u8, it.next().?, "c"));
......@@ -750,18 +749,21 @@ test "mem.split (multibyte)" {
750749}
751750
752751/// Returns an iterator that iterates over the slices of `buffer` that
753/// seperates by bytes in `delimiter`.
752/// are separated by bytes in `delimiter`.
754753/// separate("abc|def||ghi", "|")
755/// Will return slices for "abc", "def", "", "ghi", null, in that order.
754/// will return slices for "abc", "def", "", "ghi", null, in that order.
756755/// If `delimiter` does not exist in buffer,
757756/// the iterator will return `buffer`, null, in that order.
757/// The delimiter length must not be zero.
758/// See also the related function `tokenize`.
759/// It is planned to rename this function to `split` before 1.0.0, like this:
760/// pub fn split(buffer: []const u8, delimiter: []const u8) SplitIterator {
758761pub fn separate(buffer: []const u8, delimiter: []const u8) SplitIterator {
762 assert(delimiter.len != 0);
759763 return SplitIterator{
760764 .index = 0,
761765 .buffer = buffer,
762 .split_bytes = delimiter,
763 .glob = false,
764 .spun = false,
766 .delimiter = delimiter,
765767 };
766768}
767769
......@@ -782,19 +784,15 @@ test "mem.separate" {
782784 assert(eql(u8, it.next().?, ""));
783785 assert(it.next() == null);
784786
785 it = separate("hello", "");
786 assert(eql(u8, it.next().?, "hello"));
787 assert(it.next() == null);
788
789787 it = separate("hello", " ");
790788 assert(eql(u8, it.next().?, "hello"));
791789 assert(it.next() == null);
792790}
793791
794792test "mem.separate (multibyte)" {
795 var it = separate("a|b,c/d e", " /,|");
793 var it = separate("a, b ,, c, d, e", ", ");
796794 assert(eql(u8, it.next().?, "a"));
797 assert(eql(u8, it.next().?, "b"));
795 assert(eql(u8, it.next().?, "b ,"));
798796 assert(eql(u8, it.next().?, "c"));
799797 assert(eql(u8, it.next().?, "d"));
800798 assert(eql(u8, it.next().?, "e"));
......@@ -819,49 +817,38 @@ test "mem.endsWith" {
819817 assert(!endsWith(u8, "Bob", "Bo"));
820818}
821819
822pub const SplitIterator = struct {
820pub const TokenIterator = struct {
823821 buffer: []const u8,
824 split_bytes: []const u8,
822 delimiter_bytes: []const u8,
825823 index: usize,
826 glob: bool,
827 spun: bool,
828824
829 /// Iterates and returns null or optionally a slice the next split segment
830 pub fn next(self: *SplitIterator) ?[]const u8 {
831 if (self.spun) {
832 if (self.index + 1 > self.buffer.len) return null;
833 self.index += 1;
834 }
835
836 self.spun = true;
837
838 if (self.glob) {
839 while (self.index < self.buffer.len and self.isSplitByte(self.buffer[self.index])) : (self.index += 1) {}
825 /// Returns a slice of the next token, or null if tokenization is complete.
826 pub fn next(self: *TokenIterator) ?[]const u8 {
827 // move to beginning of token
828 while (self.index < self.buffer.len and self.isSplitByte(self.buffer[self.index])) : (self.index += 1) {}
829 const start = self.index;
830 if (start == self.buffer.len) {
831 return null;
840832 }
841833
842 var cursor = self.index;
843 while (cursor < self.buffer.len and !self.isSplitByte(self.buffer[cursor])) : (cursor += 1) {}
844
845 defer self.index = cursor;
834 // move to end of token
835 while (self.index < self.buffer.len and !self.isSplitByte(self.buffer[self.index])) : (self.index += 1) {}
836 const end = self.index;
846837
847 if (cursor == self.buffer.len) {
848 return if (self.glob and self.index == cursor and self.index > 0) null else self.buffer[self.index..];
849 }
850
851 return self.buffer[self.index..cursor];
838 return self.buffer[start..end];
852839 }
853840
854841 /// Returns a slice of the remaining bytes. Does not affect iterator state.
855 pub fn rest(self: *const SplitIterator) []const u8 {
842 pub fn rest(self: TokenIterator) []const u8 {
856843 // move to beginning of token
857844 var index: usize = self.index;
858845 while (index < self.buffer.len and self.isSplitByte(self.buffer[index])) : (index += 1) {}
859846 return self.buffer[index..];
860847 }
861848
862 fn isSplitByte(self: *const SplitIterator, byte: u8) bool {
863 for (self.split_bytes) |split_byte| {
864 if (byte == split_byte) {
849 fn isSplitByte(self: TokenIterator, byte: u8) bool {
850 for (self.delimiter_bytes) |delimiter_byte| {
851 if (byte == delimiter_byte) {
865852 return true;
866853 }
867854 }
......@@ -869,6 +856,32 @@ pub const SplitIterator = struct {
869856 }
870857};
871858
859pub const SplitIterator = struct {
860 buffer: []const u8,
861 index: ?usize,
862 delimiter: []const u8,
863
864 /// Returns a slice of the next field, or null if splitting is complete.
865 pub fn next(self: *SplitIterator) ?[]const u8 {
866 const start = self.index orelse return null;
867 const end = if (indexOfPos(u8, self.buffer, start, self.delimiter)) |delim_start| blk: {
868 self.index = delim_start + self.delimiter.len;
869 break :blk delim_start;
870 } else blk: {
871 self.index = null;
872 break :blk self.buffer.len;
873 };
874 return self.buffer[start..end];
875 }
876
877 /// Returns a slice of the remaining bytes. Does not affect iterator state.
878 pub fn rest(self: SplitIterator) []const u8 {
879 const end = self.buffer.len;
880 const start = self.index orelse end;
881 return self.buffer[start..end];
882 }
883};
884
872885/// Naively combines a series of strings with a separator.
873886/// Allocates memory for the result, which must be freed by the caller.
874887pub fn join(allocator: *Allocator, sep: u8, strings: ...) ![]u8 {
std/os/child_process.zig+1-1
......@@ -595,7 +595,7 @@ pub const ChildProcess = struct {
595595 const PATH = try os.getEnvVarOwned(self.allocator, "PATH");
596596 defer self.allocator.free(PATH);
597597
598 var it = mem.split(PATH, ";");
598 var it = mem.tokenize(PATH, ";");
599599 while (it.next()) |search_path| {
600600 const joined_path = try os.path.join(self.allocator, search_path, app_name);
601601 defer self.allocator.free(joined_path);
std/os/index.zig+1-1
......@@ -608,7 +608,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: *const BufMap, allocator:
608608 // +1 for the null terminating byte
609609 const path_buf = try allocator.alloc(u8, PATH.len + exe_path.len + 2);
610610 defer allocator.free(path_buf);
611 var it = mem.split(PATH, ":");
611 var it = mem.tokenize(PATH, ":");
612612 var seen_eacces = false;
613613 var err: usize = undefined;
614614 while (it.next()) |search_path| {
std/os/path.zig+23-21
......@@ -184,7 +184,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
184184 return relative_path;
185185 }
186186
187 var it = mem.split(path, []u8{this_sep});
187 var it = mem.tokenize(path, []u8{this_sep});
188188 _ = (it.next() orelse return relative_path);
189189 _ = (it.next() orelse return relative_path);
190190 return WindowsPath{
......@@ -202,7 +202,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
202202 return relative_path;
203203 }
204204
205 var it = mem.split(path, []u8{this_sep});
205 var it = mem.tokenize(path, []u8{this_sep});
206206 _ = (it.next() orelse return relative_path);
207207 _ = (it.next() orelse return relative_path);
208208 return WindowsPath{
......@@ -264,8 +264,8 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) bool {
264264 const sep1 = ns1[0];
265265 const sep2 = ns2[0];
266266
267 var it1 = mem.split(ns1, []u8{sep1});
268 var it2 = mem.split(ns2, []u8{sep2});
267 var it1 = mem.tokenize(ns1, []u8{sep1});
268 var it2 = mem.tokenize(ns2, []u8{sep2});
269269
270270 // TODO ASCII is wrong, we actually need full unicode support to compare paths.
271271 return asciiEqlIgnoreCase(it1.next().?, it2.next().?);
......@@ -285,8 +285,8 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8
285285 const sep1 = p1[0];
286286 const sep2 = p2[0];
287287
288 var it1 = mem.split(p1, []u8{sep1});
289 var it2 = mem.split(p2, []u8{sep2});
288 var it1 = mem.tokenize(p1, []u8{sep1});
289 var it2 = mem.tokenize(p2, []u8{sep2});
290290
291291 // TODO ASCII is wrong, we actually need full unicode support to compare paths.
292292 return asciiEqlIgnoreCase(it1.next().?, it2.next().?) and asciiEqlIgnoreCase(it1.next().?, it2.next().?);
......@@ -337,6 +337,8 @@ pub fn resolveSlice(allocator: *Allocator, paths: []const []const u8) ![]u8 {
337337/// If all paths are relative it uses the current working directory as a starting point.
338338/// Each drive has its own current working directory.
339339/// Path separators are canonicalized to '\\' and drives are canonicalized to capital letters.
340/// Note: all usage of this function should be audited due to the existence of symlinks.
341/// Without performing actual syscalls, resolving `..` could be incorrect.
340342pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
341343 if (paths.len == 0) {
342344 assert(is_windows); // resolveWindows called on non windows can't use getCwd
......@@ -416,7 +418,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
416418 },
417419 WindowsPath.Kind.NetworkShare => {
418420 result = try allocator.alloc(u8, max_size);
419 var it = mem.split(paths[first_index], "/\\");
421 var it = mem.tokenize(paths[first_index], "/\\");
420422 const server_name = it.next().?;
421423 const other_name = it.next().?;
422424
......@@ -483,7 +485,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
483485 if (!correct_disk_designator) {
484486 continue;
485487 }
486 var it = mem.split(p[parsed.disk_designator.len..], "/\\");
488 var it = mem.tokenize(p[parsed.disk_designator.len..], "/\\");
487489 while (it.next()) |component| {
488490 if (mem.eql(u8, component, ".")) {
489491 continue;
......@@ -516,6 +518,8 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
516518/// It resolves "." and "..".
517519/// The result does not have a trailing path separator.
518520/// If all paths are relative it uses the current working directory as a starting point.
521/// Note: all usage of this function should be audited due to the existence of symlinks.
522/// Without performing actual syscalls, resolving `..` could be incorrect.
519523pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
520524 if (paths.len == 0) {
521525 assert(!is_windows); // resolvePosix called on windows can't use getCwd
......@@ -550,7 +554,7 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
550554 errdefer allocator.free(result);
551555
552556 for (paths[first_index..]) |p, i| {
553 var it = mem.split(p, "/");
557 var it = mem.tokenize(p, "/");
554558 while (it.next()) |component| {
555559 if (mem.eql(u8, component, ".")) {
556560 continue;
......@@ -937,8 +941,8 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8)
937941 return resolved_to;
938942 }
939943
940 var from_it = mem.split(resolved_from, "/\\");
941 var to_it = mem.split(resolved_to, "/\\");
944 var from_it = mem.tokenize(resolved_from, "/\\");
945 var to_it = mem.tokenize(resolved_to, "/\\");
942946 while (true) {
943947 const from_component = from_it.next() orelse return mem.dupe(allocator, u8, to_it.rest());
944948 const to_rest = to_it.rest();
......@@ -967,14 +971,12 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8)
967971 // shave off the trailing slash
968972 result_index -= 1;
969973
970 if (to_rest.len > 0) {
971 var rest_it = mem.split(to_rest, "/\\");
972 while (rest_it.next()) |to_component| {
973 result[result_index] = '\\';
974 result_index += 1;
975 mem.copy(u8, result[result_index..], to_component);
976 result_index += to_component.len;
977 }
974 var rest_it = mem.tokenize(to_rest, "/\\");
975 while (rest_it.next()) |to_component| {
976 result[result_index] = '\\';
977 result_index += 1;
978 mem.copy(u8, result[result_index..], to_component);
979 result_index += to_component.len;
978980 }
979981
980982 return result[0..result_index];
......@@ -990,8 +992,8 @@ pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![
990992 const resolved_to = try resolvePosix(allocator, [][]const u8{to});
991993 defer allocator.free(resolved_to);
992994
993 var from_it = mem.split(resolved_from, "/");
994 var to_it = mem.split(resolved_to, "/");
995 var from_it = mem.tokenize(resolved_from, "/");
996 var to_it = mem.tokenize(resolved_to, "/");
995997 while (true) {
996998 const from_component = from_it.next() orelse return mem.dupe(allocator, u8, to_it.rest());
997999 const to_rest = to_it.rest();