14 .TH str 3mLib "20 June 1999" mLib
16 str \- small string utilities
19 .B "#include <mLib/str.h>"
21 .BI "char *str_getword(char **" pp );
22 .BI "size_t str_split(char *" p ", char *" v "[], size_t " c ", char **" rest );
23 .BI "void str_sanitize(char *" d ", const char *" p ", size_t " sz );
28 contains a few small utility functions for manipulating null-terminated
33 extracts the next whitespace-delimited word from a string. The
36 is the address of a pointer into the string: this pointer is updated by
38 so that it can extract the following word on the next call and so on.
39 The return value is the address of the next word, appropriately null
40 terminated. A null pointer is returned if the entire remainder of the
41 string is whitespace. Note that
43 modifies the string as it goes, to null-terminate the individual words.
47 divides a string into whitespace-separated words. The arguments are as
51 The address of the string to split. The string is modified by having
52 null terminators written after each word extracted.
55 The address of an array of pointers to characters. This array will be
58 the first entry will point to the first word extracted from the string,
59 and so on. If there aren't enough words in the string, the remaining
60 array elements are filled with null pointers.
63 The maxmimum number of words to extract; also, the number of elements in
68 The address of a pointer in which to store the address of the remainder
69 of the string. Leading whitespace is removed from the remainder before
70 storing. If the remainder string is empty, a null pointer is stored
73 is null, the remainder pointer is discarded.
77 is the number of words extracted from the input string.
83 characters from the string
87 The result string is null terminated. Any nonprinting characters in
89 are replaced by an underscore
96 char p[] = " alpha beta gamma delta ";
101 n = str_split(p, v, 3, &q);
103 following the call to
106 will have the value 3,
120 (note the trailing space).
122 Similarly, given the string
123 .B """\ alpha\ \ beta\ """
126 will be assigned the value 2,
130 will have the same values as last time, and
136 Mark Wooding, <mdw@nsict.org>