|
14 | 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
15 | 15 | *) |
16 | 16 |
|
17 | | -module Char = struct |
18 | | - include Char |
19 | | - |
20 | | -#if OCAML_VERSION < (4, 3, 0) |
21 | | - let equal x y = Char.compare x y = 0 |
22 | | -#endif |
23 | | -end |
24 | | - |
25 | | -module String = struct |
26 | | - include String |
27 | | - |
28 | | -#if OCAML_VERSION < (4, 3, 0) |
29 | | - let equal x y = String.compare x y = 0 |
30 | | -#endif |
31 | | - |
32 | | -#if OCAML_VERSION < (4, 4, 0) |
33 | | - let split_on_char sep s = |
34 | | - let r = ref [] in |
35 | | - let j = ref (String.length s) in |
36 | | - for i = String.length s - 1 downto 0 do |
37 | | - if String.unsafe_get s i = sep then begin |
38 | | - r := String.sub s (i + 1) (!j - i - 1) :: !r; |
39 | | - j := i |
40 | | - end |
41 | | - done; |
42 | | - String.sub s 0 !j :: !r |
43 | | -#endif |
44 | | - |
45 | | -#if OCAML_VERSION < (4, 5, 0) |
46 | | - let rec index_rec_opt s lim i c = |
47 | | - if i >= lim then None else |
48 | | - if unsafe_get s i = c then Some i else index_rec_opt s lim (i + 1) c |
49 | | - |
50 | | - let index_opt s c = index_rec_opt s (length s) 0 c |
51 | | -#endif |
52 | | - |
53 | | -#if OCAML_VERSION < (4, 3, 0) |
54 | | - let capitalize_ascii = String.capitalize (* deprecated >= 4.3.0 *) |
55 | | -#endif |
56 | | -end |
57 | | - |
58 | | -module Filename = struct |
59 | | - include Filename |
60 | | - |
61 | | -#if OCAML_VERSION < (4, 4, 0) |
62 | | - let is_dir_sep s i = s.[i] = '/' (* Unix only *) |
63 | | - |
64 | | - let extension_len name = |
65 | | - let rec check i0 i = |
66 | | - if i < 0 || is_dir_sep name i then 0 |
67 | | - else if name.[i] = '.' then check i0 (i - 1) |
68 | | - else String.length name - i0 |
69 | | - in |
70 | | - let rec search_dot i = |
71 | | - if i < 0 || is_dir_sep name i then 0 |
72 | | - else if name.[i] = '.' then check i (i - 1) |
73 | | - else search_dot (i - 1) |
74 | | - in |
75 | | - search_dot (String.length name - 1) |
76 | | - |
77 | | - let extension name = |
78 | | - let l = extension_len name in |
79 | | - if l = 0 then "" else String.sub name (String.length name - l) l |
80 | | - |
81 | | - let remove_extension name = |
82 | | - let l = extension_len name in |
83 | | - if l = 0 then name else String.sub name 0 (String.length name - l) |
84 | | -#endif |
85 | | -end |
86 | | - |
87 | | -module List = struct |
88 | | - include List |
89 | | - |
90 | | -#if OCAML_VERSION < (4, 8, 0) |
91 | | - let filter_map f = |
92 | | - let rec aux accu = function |
93 | | - | [] -> rev accu |
94 | | - | x :: l -> |
95 | | - match f x with |
96 | | - | None -> aux accu l |
97 | | - | Some v -> aux (v :: accu) l |
98 | | - in |
99 | | - aux [] |
100 | | -#endif |
101 | | - |
102 | | -#if OCAML_VERSION < (4, 6, 0) |
103 | | - let rec init_aux i n f = |
104 | | - if i >= n then [] |
105 | | - else (f i) :: init_aux (i+1) n f |
106 | | - |
107 | | - let init n f = init_aux 0 n f |
108 | | -#endif |
109 | | - |
110 | | -#if OCAML_VERSION < (4, 5, 0) |
111 | | - let rec find_opt p = function |
112 | | - | [] -> None |
113 | | - | x :: l -> if p x then Some x else find_opt p l |
114 | | - |
115 | | - let rec compare_length_with l n = |
116 | | - match l with |
117 | | - | [] -> |
118 | | - if n = 0 then 0 else |
119 | | - if n > 0 then -1 else 1 |
120 | | - | _ :: l -> |
121 | | - if n <= 0 then 1 else |
122 | | - compare_length_with l (n-1) |
123 | | -#endif |
124 | | - |
125 | | -#if OCAML_VERSION < (4, 3, 0) |
126 | | - let cons x xs = x :: xs |
127 | | -#endif |
128 | | -end |
129 | | - |
130 | | -module Warnings = struct |
131 | | - include Warnings |
132 | | - |
133 | | -#if OCAML_VERSION < (4, 3, 0) |
134 | | - (* Can't be overriden *) |
135 | | - let reset_fatal () = () |
136 | | -#endif |
137 | | -end |
138 | | - |
139 | | -module Lexer = struct |
140 | | - include Lexer |
141 | | - |
142 | | -#if OCAML_VERSION < (4, 3, 0) |
143 | | - let handle_docstrings = ref true |
144 | | -#endif |
145 | | -end |
146 | | - |
147 | | -#if OCAML_VERSION < (4, 4, 0) |
148 | | -module Env = struct |
149 | | - include Env |
150 | | - |
151 | | - (* Can't be overriden *) |
152 | | - let without_cmis f x = f x |
153 | | -end |
154 | | -#endif |
155 | | - |
156 | 17 | #if OCAML_VERSION >= (4, 9, 0) |
157 | 18 | let init_path () = Compmisc.init_path () |
158 | 19 | #else |
|
0 commit comments