diff options
author | Nicolas Pouillard <np@nicolaspouillard.fr> | 2008-10-01 08:36:26 +0000 |
---|---|---|
committer | Nicolas Pouillard <np@nicolaspouillard.fr> | 2008-10-01 08:36:26 +0000 |
commit | 1ede9c14d9ad2c132b24d1963f22b85d879c4f29 (patch) | |
tree | 38c9f0fdec3fe663968a53ae21c8a9477ccfb342 | |
parent | 5f5a19a54113bb584f49f59ae6c0e09389f85bad (diff) |
ocamlbuild: Progress on PR#4575 handle '\r' in chomp.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@9044 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r-- | ocamlbuild/my_std.ml | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/ocamlbuild/my_std.ml b/ocamlbuild/my_std.ml index d8b028d8d..50f29f858 100644 --- a/ocamlbuild/my_std.ml +++ b/ocamlbuild/my_std.ml @@ -127,10 +127,13 @@ module String = struct let print f s = fprintf f "%S" s 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 - if ls = 0 then s - else if s.[ls-1] = '\n' then sub s 0 (ls - 1) - else s + let n = cut ls in + if n = ls then s else sub s 0 n let before s pos = sub s 0 pos let after s pos = sub s pos (length s - pos) |