| ... | @@ -484,8 +484,13 @@ pub const Path = struct { | ... | @@ -484,8 +484,13 @@ pub const Path = struct { |
| 484 | assert(fs.path.isAbsolute(sub_path)); | 484 | assert(fs.path.isAbsolute(sub_path)); |
| 485 | if (!std.mem.startsWith(u8, sub_path, cwd_path)) return sub_path; | 485 | if (!std.mem.startsWith(u8, sub_path, cwd_path)) return sub_path; |
| 486 | if (sub_path.len == cwd_path.len) return "."; // the strings are equal | 486 | if (sub_path.len == cwd_path.len) return "."; // the strings are equal |
| 487 | if (sub_path[cwd_path.len] != fs.path.sep) return sub_path; // last component before cwd differs | 487 | const path_sep_index = path_sep_index: { |
| 488 | return sub_path[cwd_path.len + 1 ..]; // remove '/path/to/cwd/' prefix | 488 | // cwd is just a root, e.g. / or C:\ |
| | 489 | if (cwd_path[cwd_path.len - 1] == fs.path.sep) break :path_sep_index cwd_path.len - 1; |
| | 490 | if (sub_path[cwd_path.len] != fs.path.sep) return sub_path; // last component before cwd differs |
| | 491 | break :path_sep_index cwd_path.len; |
| | 492 | }; |
| | 493 | return sub_path[path_sep_index + 1 ..]; // remove '/path/to/cwd/' prefix |
| 489 | } | 494 | } |
| 490 | | 495 | |
| 491 | /// From an unresolved path (which can be made of multiple not-yet-joined strings), construct a | 496 | /// From an unresolved path (which can be made of multiple not-yet-joined strings), construct a |
| ... | @@ -672,8 +677,13 @@ pub const Path = struct { | ... | @@ -672,8 +677,13 @@ pub const Path = struct { |
| 672 | if (!mem.startsWith(u8, inner.sub_path, outer.sub_path)) return .no; | 677 | if (!mem.startsWith(u8, inner.sub_path, outer.sub_path)) return .no; |
| 673 | if (inner.sub_path.len == outer.sub_path.len) return .no; | 678 | if (inner.sub_path.len == outer.sub_path.len) return .no; |
| 674 | if (outer.sub_path.len == 0) return .{ .yes = inner.sub_path }; | 679 | if (outer.sub_path.len == 0) return .{ .yes = inner.sub_path }; |
| 675 | if (inner.sub_path[outer.sub_path.len] != fs.path.sep) return .no; | 680 | const path_sep_index = path_sep_index: { |
| 676 | return .{ .yes = inner.sub_path[outer.sub_path.len + 1 ..] }; | 681 | // outer is just a root, e.g. / or C:\ |
| | 682 | if (outer.sub_path[outer.sub_path.len - 1] == fs.path.sep) break :path_sep_index outer.sub_path.len - 1; |
| | 683 | if (inner.sub_path[outer.sub_path.len] != fs.path.sep) return .no; |
| | 684 | break :path_sep_index outer.sub_path.len; |
| | 685 | }; |
| | 686 | return .{ .yes = inner.sub_path[path_sep_index + 1 ..] }; |
| 677 | } | 687 | } |
| 678 | | 688 | |
| 679 | /// Returns whether this `Path` is illegal to have as a user-imported `Zcu.File` (including | 689 | /// Returns whether this `Path` is illegal to have as a user-imported `Zcu.File` (including |