1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
open Import
open Json.Conv
type t = string [@@deriving_inline yojson]
let _ = fun (_ : t) -> ()
let t_of_yojson = (string_of_yojson : Ppx_yojson_conv_lib.Yojson.Safe.t -> t)
let _ = t_of_yojson
let yojson_of_t = (yojson_of_string : t -> Ppx_yojson_conv_lib.Yojson.Safe.t)
let _ = yojson_of_t
[@@@end]
let equal = String.equal
let hash = String.hash
let to_dyn = String.to_dyn
let to_string uri = uri
let proto =
match Sys.win32 with
| true -> "file:///"
| false -> "file://"
let to_path (uri : t) =
let path =
match String.drop_prefix ~prefix:proto uri with
| Some path -> path
| None -> uri
in
path
|> String.replace_all ~pattern:"\\" ~with_:"/"
|> String.replace_all ~pattern:"%3A" ~with_:":"
|> String.replace_all ~pattern:"%5C" ~with_:"/"
let of_path (path : string) =
let path =
path
|> String.replace_all ~pattern:"\\" ~with_:"/"
|> String.replace_all ~pattern:":" ~with_:"%3A"
in
proto ^ path
let pp fmt uri = Format.fprintf fmt "%s" uri