-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.ml
More file actions
35 lines (35 loc) · 924 Bytes
/
util.ml
File metadata and controls
35 lines (35 loc) · 924 Bytes
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
let
strip_whitespace str = (
if str = "" then "" else
let search_pos init p next =
let rec search i =
if p i then raise(Failure "empty") else
match str.[i] with
| ' ' | '\n' | '\r' | '\t' -> search (next i)
| _ -> i
in
search init in let len = String.length str in try
let left = search_pos 0 (fun i -> i >= len) (succ)
and right = search_pos (len - 1) (fun i -> i < 0) (pred)
in
String.sub str left (right - left + 1) with | Failure "empty" -> ""
)
;;
let
file_contents filename =
let lines = ref [] in
let chan = open_in filename in
try
while true; do
lines := input_line chan :: !lines
done;""
with End_of_file ->
close_in chan;
(String.concat "\n" (List.rev !lines))
;;
let
relativePath pathname =
let cppmlPath = Sys.argv.(0) in
(* hack out the last five characters *)
(String.sub cppmlPath 0 (String.length cppmlPath - 5)) ^ pathname
;;