2 * Copyright (C) 2009-2010 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 (* Please read generator/README first. *)
21 (** Useful utility functions. *)
23 val uuidgen : unit -> string
24 (** Generate a random UUID (used in tests). *)
26 type rstructs_used_t = RStructOnly | RStructListOnly | RStructAndList
27 (** Return type of {!rstructs_used_by}. *)
29 val rstructs_used_by : Generator_types.action list -> (string * rstructs_used_t) list
30 (** Returns a list of RStruct/RStructList structs that are returned
33 val failwithf : ('a, unit, string, 'b) format4 -> 'a
34 (** Like [failwith] but supports printf-like arguments. *)
36 val unique : unit -> int
37 (** Returns a unique number each time called. *)
39 val replace_char : string -> char -> char -> string
40 (** Replace character in string. *)
42 val isspace : char -> bool
43 (** Return true if char is a whitespace character. *)
45 val triml : ?test:(char -> bool) -> string -> string
48 val trimr : ?test:(char -> bool) -> string -> string
51 val trim : ?test:(char -> bool) -> string -> string
52 (** Trim left and right. *)
54 val find : string -> string -> int
55 (** [find str sub] searches for [sub] in [str], returning the index
56 or -1 if not found. *)
58 val replace_str : string -> string -> string -> string
59 (** [replace_str str s1 s2] replaces [s1] with [s2] throughout [str]. *)
61 val string_split : string -> string -> string list
62 (** [string_split sep str] splits [str] at [sep]. *)
64 val files_equal : string -> string -> bool
65 (** [files_equal filename1 filename2] returns true if the files contain
68 val filter_map : ('a -> 'b option) -> 'a list -> 'b list
70 val find_map : ('a -> 'b option) -> 'a list -> 'b
72 val iteri : (int -> 'a -> unit) -> 'a list -> unit
74 val mapi : (int -> 'a -> 'b) -> 'a list -> 'b list
76 val count_chars : char -> string -> int
77 (** Count number of times the character occurs in string. *)
79 val explode : string -> char list
80 (** Explode a string into a list of characters. *)
82 val map_chars : (char -> 'a) -> string -> 'a list
83 (** Explode string, then map function over the characters. *)
85 val name_of_argt : Generator_types.argt -> string
86 (** Extract argument name. *)
88 val seq_of_test : Generator_types.test -> Generator_types.seq
89 (** Extract test sequence from a test. *)
91 val c_quote : string -> string
92 (** Perform quoting on a string so it is safe to include in a C source file. *)
94 val pod2text : width:int -> string -> string -> string list
95 (** [pod2text ~width name longdesc] converts the POD in [longdesc] to
96 plain ASCII lines of text. This is the slowest part of
97 autogeneration, so the results are memoized into a temporary
100 val action_compare : Generator_types.action -> Generator_types.action -> int
101 (** Compare the names of two actions, for sorting. *)
103 val chars : char -> int -> string
104 (** [chars c n] creates a string containing character c repeated n times. *)
106 val spaces : int -> string
107 (** [spaces n] creates a string of n spaces. *)