utils: Add unique () function.
[goals.git] / src / utils.mli
1 (* Goalfile utilities
2  * Copyright (C) 2019 Richard W.M. Jones
3  * Copyright (C) 2019 Red Hat Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  *)
19
20 val failwithf : ('a, unit, string, 'b) format4 -> 'a
21 (** Like [failwith] but supports printf-like arguments. *)
22
23 val (//) : string -> string -> string
24 (** The {!Filename.concat} function. *)
25
26 val is_directory : string -> bool
27 (** Return true iff parameter is a directory. *)
28
29 val unique : unit -> int
30 (** Returns a unique number each time called. *)
31
32 val filter_map : ('a -> 'b option) -> 'a list -> 'b list
33 (** [filter_map f l] applies [f] to every element of [l], filters
34     out the [None] elements and returns the list of the arguments of
35     the [Some] elements. *)
36
37 val string_find : string -> string -> int
38 (** [string_find str sub] finds the index of [sub] in [str].  If
39     not found, returns -1. *)
40
41 val split : string -> string -> string * string
42 (** [split sep str] splits [str] at the first occurrence of the
43     separator [sep], returning the part before and the part after.
44     If separator is not found, return the whole string and an
45     empty string. *)
46
47 val nsplit : ?max:int -> string -> string -> string list
48 (** [nsplit ?max sep str] splits [str] into multiple strings at each
49     separator [sep].
50
51     As with the Perl split function, you can give an optional
52     [?max] parameter to limit the number of strings returned.  The
53     final element of the list will contain the remainder of the
54     input string. *)
55
56 val isspace : char -> bool
57 val triml : ?test:(char -> bool) -> string -> string
58 val trimr : ?test:(char -> bool) -> string -> string
59 val trim : ?test:(char -> bool) -> string -> string
60 (** Trim strings at left, right or both. *)
61
62 val absolute_path : string -> string
63 (** Convert any path into an absolute path. *)