From 60cf834c41107f4d03d327a95e3cc245d4162ee4 Mon Sep 17 00:00:00 2001 From: Johannes Kanig Date: Thu, 29 Oct 2015 08:22:44 +0900 Subject: [PATCH] OA26-022 move string utility function to string utility module --- src/transform/intro_vc_vars_counterexmp.ml | 8 +------- src/util/strings.ml | 6 ++++++ src/util/strings.mli | 4 ++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/transform/intro_vc_vars_counterexmp.ml b/src/transform/intro_vc_vars_counterexmp.ml index df7a57032..e94d5cce0 100644 --- a/src/transform/intro_vc_vars_counterexmp.ml +++ b/src/transform/intro_vc_vars_counterexmp.ml @@ -194,12 +194,6 @@ let () = Trans.register_transform "intro_vc_vars_counterexmp" intro_vc_vars_counterexmp ~desc:"Introduce." -let rec string_join sep l = - match l with - | [] -> "" - | [x] -> x - | x :: rest -> x ^ sep ^ string_join sep rest - let get_location_of_vc task = let meta_args = Task.on_meta_excl meta_vc_location task in match meta_args with @@ -214,7 +208,7 @@ let get_location_of_vc task = let line = int_of_string line in let col1 = int_of_string col1 in let col2 = int_of_string col2 in - let filename = string_join ":" (List.rev rest) in + let filename = Strings.join ":" (List.rev rest) in Some (Loc.user_position filename line col1 col2) | _ -> None in loc diff --git a/src/util/strings.ml b/src/util/strings.ml index f541f9eea..c84814889 100644 --- a/src/util/strings.ml +++ b/src/util/strings.ml @@ -39,6 +39,12 @@ let rev_bounded_split c s n = let bounded_split c s n = List.rev (rev_bounded_split c s n) +let rec join sep l = + match l with + | [] -> "" + | [x] -> x + | x :: rest -> x ^ sep ^ join sep rest + let ends_with s suf = let rec aux s suf suflen offset i = i >= suflen || (s.[i + offset] = suf.[i] diff --git a/src/util/strings.mli b/src/util/strings.mli index ef6a32ad4..00727a502 100644 --- a/src/util/strings.mli +++ b/src/util/strings.mli @@ -32,6 +32,10 @@ val bounded_split : char -> string -> int -> string list [n] substring at most. The concatenation of returned substrings is equal to the string s.*) +val join : string -> string list -> string +(** [join sep l] joins all the strings in [l] together, in the same + order, separating them by [sep] *) + val ends_with : string -> string -> bool (** test if a string ends with another *) -- GitLab