14 .TH str 3 "20 June 1999" mLib
16 str \- small string utilities
22 .B "#include <mLib/str.h>"
24 .BI "char *str_getword(char **" pp );
25 .BI "size_t str_split(char *" p ", char *" v "[], size_t " c ", char **" rest );
26 .BI "void str_sanitize(char *" d ", const char *" p ", size_t " sz );
31 contains a few small utility functions for manipulating null-terminated
36 extracts the next whitespace-delimited word from a string. The
39 is the address of a pointer into the string: this pointer is updated by
41 so that it can extract the following word on the next call and so on.
42 The return value is the address of the next word, appropriately null
43 terminated. A null pointer is returned if the entire remainder of the
44 string is whitespace. Note that
46 modifies the string as it goes, to null-terminate the individual words.
50 divides a string into whitespace-separated words. The arguments are as
54 The address of the string to split. The string is modified by having
55 null terminators written after each word extracted.
58 The address of an array of pointers to characters. This array will be
61 the first entry will point to the first word extracted from the string,
62 and so on. If there aren't enough words in the string, the remaining
63 array elements are filled with null pointers.
66 The maximum number of words to extract; also, the number of elements in
71 The address of a pointer in which to store the address of the remainder
72 of the string. Leading whitespace is removed from the remainder before
73 storing. If the remainder string is empty, a null pointer is stored
76 is null, the remainder pointer is discarded.
80 is the number of words extracted from the input string.
86 characters from the string
90 The result string is null terminated. Any nonprinting characters in
92 are replaced by an underscore
99 char p[] = " alpha beta gamma delta ";
104 n = str_split(p, v, 3, &q);
106 following the call to
109 will have the value 3,
123 (note the trailing space).
125 Similarly, given the string
126 .B """\ alpha\ \ beta\ """
129 will be assigned the value 2,
133 will have the same values as last time, and
141 Mark Wooding, <mdw@nsict.org>