diff options
author | glondu <glondu@85f007b7-540e-0410-9357-904b9bb8a0f7> | 2009-01-08 17:58:36 +0000 |
---|---|---|
committer | glondu <glondu@85f007b7-540e-0410-9357-904b9bb8a0f7> | 2009-01-08 17:58:36 +0000 |
commit | 2784afbbb12ce92df1e8c8ad97d081969cfbea08 (patch) | |
tree | c3390af8d419c79a28365595e61a9f6ae6d64cdf | |
parent | b80e47d26cd703da5195d6134c74c485d8624b6f (diff) |
Remove trailing newlines in outputs of X -where
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@11768 85f007b7-540e-0410-9357-904b9bb8a0f7
-rw-r--r-- | lib/envars.ml | 4 | ||||
-rw-r--r-- | lib/util.ml | 18 | ||||
-rw-r--r-- | lib/util.mli | 2 |
3 files changed, 22 insertions, 2 deletions
diff --git a/lib/envars.ml b/lib/envars.ml index e67fc32d9..867297a86 100644 --- a/lib/envars.ml +++ b/lib/envars.ml @@ -63,7 +63,7 @@ let camllib () = let camlbin = camlbin () in let com = (Filename.concat camlbin "ocamlc") ^ " -where" in let _,res = System.run_command (fun x -> x) (fun _ -> ()) com in - res + Util.strip res (* TODO : essayer aussi camlbin *) let camlp4bin () = @@ -78,6 +78,6 @@ let camlp4lib () = let camlp4bin = camlp4bin () in let com = (Filename.concat camlp4bin Coq_config.camlp4) ^ " -where" in let _,res = System.run_command (fun x -> x) (fun _ -> ()) com in - res + Util.strip res diff --git a/lib/util.ml b/lib/util.ml index fe715f0a7..93032140c 100644 --- a/lib/util.ml +++ b/lib/util.ml @@ -59,6 +59,9 @@ let is_letter c = (c >= 'a' && c <= 'z') or (c >= 'A' && c <= 'Z') let is_digit c = (c >= '0' && c <= '9') let is_ident_tail c = is_letter c or is_digit c or c = '\'' or c = '_' +let is_blank = function + | ' ' | '\r' | '\t' | '\n' -> true + | _ -> false (* Strings *) @@ -73,6 +76,21 @@ let explode s = let implode sl = String.concat "" sl +let strip s = + let n = String.length s in + let rec lstrip_rec i = + if i < n && is_blank s.[i] then + lstrip_rec (i+1) + else i + in + let rec rstrip_rec i = + if i >= 0 && is_blank s.[i] then + rstrip_rec (i-1) + else i + in + let a = lstrip_rec 0 and b = rstrip_rec (n-1) in + String.sub s a (b-a+1) + (* substring searching... *) (* gdzie = where, co = what *) diff --git a/lib/util.mli b/lib/util.mli index b6403fd73..7af5816ea 100644 --- a/lib/util.mli +++ b/lib/util.mli @@ -68,11 +68,13 @@ val pi3 : 'a * 'b * 'c -> 'c val is_letter : char -> bool val is_digit : char -> bool val is_ident_tail : char -> bool +val is_blank : char -> bool (*s Strings. *) val explode : string -> string list val implode : string list -> string +val strip : string -> string val string_index_from : string -> int -> string -> int val string_string_contains : where:string -> what:string -> bool val plural : int -> string -> string |