fun line ->
Pcre.pmatch ~rex:blank_line_RE line
+let normalize_dir s = (* append "/" if missing *)
+ let len = String.length s in
+ try
+ if s.[len - 1] = '/' then s
+ else s ^ "/"
+ with Invalid_argument _ -> (* string is empty *) "/"
+
+let strip_trailing_slash s =
+ try
+ let len = String.length s in
+ if s.[len - 1] = '/' then String.sub s 0 (len - 1)
+ else s
+ with Invalid_argument _ -> s
+
+let strip_suffix ~suffix s =
+ try
+ let s_len = String.length s in
+ let suffix_len = String.length suffix in
+ let suffix_sub = String.sub s (s_len - suffix_len) suffix_len in
+ if suffix_sub <> suffix then raise (Invalid_argument "");
+ String.sub s 0 (s_len - suffix_len)
+ with Invalid_argument _ ->
+ raise (Invalid_argument "Http_getter_misc.strip_suffix")
+
+let rec list_uniq = function
+ | [] -> []
+ | h::[] -> [h]
+ | h1::h2::tl when h1 = h2 -> list_uniq (h2 :: tl)
+ | h1::tl (* when h1 <> h2 *) -> h1 :: list_uniq tl
+
+let extension s =
+ try
+ let idx = String.rindex s '.' in
+ String.sub s idx (String.length s - idx)
+ with Not_found -> ""
+
+let temp_file_of_uri uri =
+ let flat_string s s' c =
+ let cs = String.copy s in
+ for i = 0 to (String.length s) - 1 do
+ if String.contains s' s.[i] then cs.[i] <- c
+ done;
+ cs
+ in
+ let user = try Unix.getlogin () with _ -> "" in
+ Filename.open_temp_file (user ^ flat_string uri ".-=:;!?/&" '_') ""
+
+let backtick cmd =
+ let ic = Unix.open_process_in cmd in
+ let res = input_line ic in
+ ignore (Unix.close_process_in ic);
+ res
+