let split = function
| "" -> ".", "."
| s ->
match skip_end_slashes s ~from:(String.length s) with
| `All_slashes -> "/", "/"
| `Ends_at basename_end ->
match string_rexists s ~f:(fun c -> c = '/') ~from:basename_end with
| None -> ".", String.sub ~pos:0 ~len:basename_end s
| Some basename_start ->
let basename =
String.sub s ~pos:basename_start
~len:(basename_end - basename_start)
in
let dirname =
match skip_end_slashes s ~from:basename_start with
| `All_slashes -> "/"
| `Ends_at dirname_end -> String.sub ~pos:0 ~len:dirname_end s
in
dirname, basename