Up

module OASISUtils

: sig

Various utilities

Author Sylvain Le Gall

Map

#
module MapExt : sig
#
module type S = sig
include Map.S
#
val add_list : 'a t -> (key * 'a) list -> 'a t

Extends a map with an association list.

#
val of_list : (key * 'a) list -> 'a t

Convert an association list to a map.

#
val to_list : 'a t -> (key * 'a) list

Convert a map to an association list.

end
#
module Make : functor (Ord : Map.OrderedType) -> S with type key = Ord.t
end
#
module MapString : MapExt.S with type key = String.t

Set

#
module SetExt : sig
#
module type S = sig
include Set.S
#
val add_list : t -> elt list -> t

Extends a set with a list.

#
val of_list : elt list -> t

Convert a list to a set.

#
val to_list : t -> elt list

Shortcut for Set.elements.

end
#
module Make : functor (Ord : Set.OrderedType) -> S with type elt = Ord.t
end
#
module SetString : SetExt.S with type elt = String.t

Set for String.

#
module SetStringCsl : SetExt.S with type elt = String.t

Set for String.

Hashtable

#
module HashStringCsl : Hashtbl.S with type key = String.t

Caseless string hashtable

Variable name

#
val varname_of_string : ?hyphen:char -> string -> string

varname_of_string ~hyphen:c s Transform a string s into a variable name, following this convention: no digit at the beginning, lowercase, only a-z and 0-9 chars. Whenever there is a problem, use an hyphen.

#
val varname_concat : ?hyphen:char -> string -> string -> string

varname_concat ~hyphen p s Concat variable name, removing hyphen at end of p and at beginning of s.

#
val is_varname : string -> bool

is_varname str Check that the string str is a valid varname. See varname_of_string for definition.

Fail with Printf.sprintf

#
val failwithf : ('a, unit, string, 'b) Pervasives.format4 -> 'a

This function raise the Failure exception just as failwith except that one specify the string raised through a format string.

Example: failwithf "Cannot do %s because of %d" str i

String

#
val compare_csl : string -> string -> int

Caseless compare function

Options

#
val may : ('a -> unit) -> 'a option -> unit

may f (Some x) calls f x or do nothing.

#
module POSIXShell : sig
#
val split : string -> string list

split s: the string s is interpreted as command line arguments and splitted into its components (un-escaped). For example split "a \"b c\" d" = ["a"; "b c"; "d"]. Note that split "" = []. It is possible that substitutions such as "$a" (resp. "$(a b)") may be transformed into "${a}" (resp. "${a b}").

#
val escape : string -> string

escape s quote s if needed to protect spaces, '"' and '\'' so it reads as a single argument in a POSIX shell command, the content of which is identical to s (interpreted with OCaml conventions). If quoted, the returned string will start and end with '"'. The original string s is returned if no quoting is necessary.

#
val unescape : string -> string

unescape s returns a string s' removing all backslashes preceding a char.

end
end