stdlib/fedora: Use grep -F when matching %fedora-rebuild-name
[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 nprocs : unit -> int
21 (** Return the number of processors on the system. *)
22
23 val failwithf : ('a, unit, string, 'b) format4 -> 'a
24 (** Like [failwith] but supports printf-like arguments. *)
25
26 val (//) : string -> string -> string
27 (** The {!Filename.concat} function. *)
28
29 val is_directory : string -> bool
30 (** Return true iff parameter is a directory. *)
31
32 val unique : unit -> int
33 (** Returns a unique number each time called. *)
34
35 val filter_map : ('a -> 'b option) -> 'a list -> 'b list
36 (** [filter_map f l] applies [f] to every element of [l], filters
37     out the [None] elements and returns the list of the arguments of
38     the [Some] elements. *)
39
40 val string_find : string -> string -> int
41 (** [string_find str sub] finds the index of [sub] in [str].  If
42     not found, returns -1. *)
43
44 val split : string -> string -> string * string
45 (** [split sep str] splits [str] at the first occurrence of the
46     separator [sep], returning the part before and the part after.
47     If separator is not found, return the whole string and an
48     empty string. *)
49
50 val nsplit : ?max:int -> string -> string -> string list
51 (** [nsplit ?max sep str] splits [str] into multiple strings at each
52     separator [sep].
53
54     As with the Perl split function, you can give an optional
55     [?max] parameter to limit the number of strings returned.  The
56     final element of the list will contain the remainder of the
57     input string. *)
58
59 val isspace : char -> bool
60 val triml : ?test:(char -> bool) -> string -> string
61 val trimr : ?test:(char -> bool) -> string -> string
62 val trim : ?test:(char -> bool) -> string -> string
63 (** Trim strings at left, right or both. *)
64
65 val absolute_path : string -> string
66 (** Convert any path into an absolute path. *)