File tree Expand file tree Collapse file tree 2 files changed +40
-3
lines changed Expand file tree Collapse file tree 2 files changed +40
-3
lines changed Original file line number Diff line number Diff line change 11type 'a t = 'a Fs .dir * Fs .path
22
3+ (* Like [Filename.is_relative] but always using "/" as the separator. *)
4+ let is_relative = function
5+ | "" -> true
6+ | x -> x.[0 ] <> '/'
7+
8+ (* Like [Filename.concat] but always using "/" as the separator. *)
9+ let concat a b =
10+ let l = String. length a in
11+ if l = 0 || a.[l - 1 ] = '/' then a ^ b
12+ else a ^ " /" ^ b
13+
314let ( / ) (dir , p1 ) p2 =
415 match p1, p2 with
5- | p1 , "" -> (dir, Filename. concat p1 p2)
6- | _ , p2 when not (Filename. is_relative p2) -> (dir, p2)
16+ | p1 , "" -> (dir, concat p1 p2)
17+ | _ , p2 when not (is_relative p2) -> (dir, p2)
718 | "." , p2 -> (dir, p2)
8- | p1 , p2 -> (dir, Filename. concat p1 p2)
19+ | p1 , p2 -> (dir, concat p1 p2)
920
1021let pp f (Resource. T (t , ops ), p ) =
1122 let module X = (val (Resource. get ops Fs.Pi. Dir )) in
Original file line number Diff line number Diff line change @@ -985,3 +985,29 @@ Exception: Failure "Simulated error".
985985+seek from end: 9
986986- : unit = ()
987987```
988+
989+ # Extending paths
990+
991+ ``` ocaml
992+ # run @@ fun env ->
993+ let base = fst env#cwd in
994+ List.iter (fun (a, b) -> traceln "%S / %S = %S" a b (snd ((base, a) / b))) [
995+ "foo", "bar";
996+ "foo/", "bar";
997+ "foo", "/bar";
998+ "foo", "";
999+ "foo/", "";
1000+ "", "";
1001+ "", "bar";
1002+ "/", "";
1003+ ]
1004+ +"foo" / "bar" = "foo/bar"
1005+ +"foo/" / "bar" = "foo/bar"
1006+ +"foo" / "/bar" = "/bar"
1007+ +"foo" / "" = "foo/"
1008+ +"foo/" / "" = "foo/"
1009+ +"" / "" = ""
1010+ +"" / "bar" = "bar"
1011+ +"/" / "" = "/"
1012+ - : unit = ()
1013+ ```
You can’t perform that action at this time.
0 commit comments