-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpath.mli
85 lines (59 loc) · 3.19 KB
/
path.mli
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
(** A minimal library for manipulating typed representations of paths.
This library is a wrapper for the {{: https://gildor478.github.io/ocaml-fileutils/} [fileutils]} library, and is therefore OS independent.
For example, a root path on Windows will have the form ["c:\\some\\...\\path"] instead of ["/some/.../path"], but we use the Unix convention below for convenience.
*)
exception InvalidRootType of string
exception InvalidRelType of string
exception InvalidNameType of string
exception UnexpectedFileExtension of string
(** A root path has the form ["/some/.../path"] *)
type root
(** A relative path has the form ["some/.../path"] *)
type rel
(** A name is the name of a file or directory, which cannot contain the character ['/'] *)
type name
(** Check well-formedness of paths. Set to true by default. *)
val check : bool ref
(** Constructor for creating a root path, if {!check} is set to true, [mk_root] will check that input is well-formed.
Raise [InvalidRootType] otherwise *)
val mk_root : string -> root
(** Constructor for creating a relative path, if {!check} is set to true, [mk_rel] will check that input is well-formed.
Raise [InvalidRelType] otherwise *)
val mk_rel : string -> rel
(** Constructor for creating a name, if {!check} is set to true, [mk_name] will check that input is well-formed.
Raise [InvalidNameType] otherwise *)
val mk_name : string -> name
(** Convert a root path to a string *)
val string_of_root : root -> string
(** Convert a relative path to a string *)
val string_of_rel : rel -> string
(** Convert a name to a string *)
val string_of_name : name -> string
(** [split path] splits a relative path into a list of names *)
val split : rel -> name list
(** [merge root path] produces the path [root'/'path] *)
val merge : root -> rel -> root
(** [merge root names] is the same as [merge] but a relative path is given as a list of names *)
val merge_lst : root -> name list -> root
(** [unroot "/some/.../path"] will return [("/", "some/.../path")] *)
val unroot : root -> root * rel
(** [add_file_ext ext path] wiil add the file extension [ext] to the {{!get_leaf} leaf} of [path], that is [path'.'ext] *)
val add_file_ext : string -> root -> root
(** [remove_file_ext ext path] removes the file extension from the file name.
Raise [UnexpectedFileExtension] if file extension does not match *)
val remove_file_ext : string -> root -> root
(** Same as [remove_file_ext], but for relative paths *)
val remove_file_ext_rel : string -> rel -> rel
(** [strip_root root path] will drop the initial substring [root] from [path], thus inversing {!merge} *)
val strip_root : root -> root -> rel
(** [get_leaf "/some/.../path/leaf"] returns the leaf of a path, that is [leaf] *)
val get_leaf : root -> name
(** Same as [get_leaf] but for relative paths *)
val get_leaf_rel : rel -> name
(** [drop_leaf "/some/.../path/leaf"] will return ["/some/.../path"] *)
val drop_leaf : root -> root
(** [hidden path] will return true if the {{!get_leaf} leaf} of [path] is a hidden file, that is starts with ['.'] *)
val hidden : root -> bool
(** Pretty print path *)
val pp_root : Format.formatter -> root -> unit
val pp_rel : Format.formatter -> rel -> unit