1 (* Utility functions. *)
8 let len = String.length s in
9 let sublen = String.length sub in
11 if i <= len-sublen then (
14 if s.[i+j] = sub.[j] then loop2 (j+1)
20 if r = -1 then loop (i+1) else r
26 let rec nsplit sep str =
27 let len = String.length str in
28 let seplen = String.length sep in
29 let i = find str sep in
32 let s' = String.sub str 0 i in
33 let s'' = String.sub str (i+seplen) (len-i-seplen) in
39 prerr_string "todo: error: ";
45 let string_of_estimate period =
46 (* We ignore the seconds, and assume every estimate is >= 1 day. *)
47 let (years, months, days, _) = Calendar.Period.ymds period in
48 let buf = Buffer.create 13 in
50 if Buffer.length buf > 0 then
51 Buffer.add_string buf ", ";
52 Buffer.add_string buf str
54 if years >= 2 then append (sprintf "%d years" years)
55 else if years = 1 then append "1 year";
56 if months >= 2 then append (sprintf "%d months" months)
57 else if months = 1 then append "1 month";
58 if days >= 2 then append (sprintf "%d days" days)
59 else if days = 1 then append "1 day";
60 let str = Buffer.contents buf in
61 if str <> "" then str else "-"