let chomp s =
let is_nl_char = function '\n' | '\r' -> true | _ -> false in
let rec cut n =
if n = 0 then 0 else if is_nl_char s.[n-1] then cut (n-1) else n
in
let ls = length s in
let n = cut ls in
if n = ls then s else sub s 0 n