3 * Functions for hacking with strings
5 * (c) 1999 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the mLib utilities library.
12 * mLib is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * mLib is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with mLib; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
35 /*----- Header files ------------------------------------------------------*/
39 /*----- Functions provided ------------------------------------------------*/
41 /* --- @str_qword@ --- *
43 * Arguments: @char **pp@ = address of pointer into string
44 * @unsigned f@ = various flags
46 * Returns: Pointer to the next space-separated possibly-quoted word from
47 * the string, or null.
49 * Use: Fetches the next word from a string. If the flag
50 * @STRF_QUOTE@ is set, the `\' character acts as an escape, and
51 * single and double quotes protect whitespace.
56 extern char *str_qword(char **/
*pp*/
, unsigned /*f*/);
58 /* --- @str_qsplit@ --- *
60 * Arguments: @char *p@ = pointer to string
61 * @char *v[]@ = pointer to array to fill in
62 * @size_t c@ = count of strings to fill in
63 * @char **rest@ = where to store the remainder of the string
64 * @unsigned f@ = flags for @str_qword@
66 * Returns: Number of strings filled in.
68 * Use: Fills an array with pointers to the individual words of a
69 * string. The string is modified in place to contain zero
70 * bytes at the word boundaries, and the words have leading
71 * and trailing space stripped off. No more than @c@ words
72 * are read; the actual number is returned as the value of the
73 * function. Unused slots in the array are populated with
74 * null bytes. If there's any string left, the address of the
75 * remainder is stored in @rest@ (if it's non-null); otherwise
76 * @rest@ is set to a null pointer.
79 extern size_t str_qsplit(char */
*p*/
, char */
*v*/
[], size_t /*c*/,
80 char **/
*rest*/
, unsigned /*f*/);
82 /* --- @str_getword@ --- *
84 * Arguments: @char **pp@ = address of pointer into string
86 * Returns: Pointer to the next space-separated word from the string,
89 * Use: Parses off space-separated words from a string. This is a
90 * compatibility veneer over @str_qword@.
93 extern char *str_getword(char **/
*pp*/
);
95 /* --- @str_split@ --- *
97 * Arguments: @char *p@ = pointer to string
98 * @char *v[]@ = pointer to array to fill in
99 * @size_t c@ = count of strings to fill in
100 * @char **rest@ = where to store the remainder of the string
102 * Returns: Number of strings filled in.
104 * Use: Fills an array with pointers to the individual words of a
105 * string. This is a compatibility veneer over @str_qsplit@.
108 extern size_t str_split(char */
*p*/
, char */
*v*/
[],
109 size_t /*c*/, char **/
*rest*/
);
111 /* --- @str_matchx@ --- *
113 * Arguments: @const char *p@ = pointer to pattern string
114 * @const char *s@ = string to compare with
115 * @unsigned f@ = various flags
117 * Returns: Nonzero if the pattern matches the string.
119 * Use: Does simple wildcard matching. This is quite nasty and more
120 * than a little slow. Supports metacharacters `*', `?' and
124 #define STRF_PREFIX 1u /* Accept if @s@ is exhausted during
125 * the attempted match */
127 extern int str_matchx(const char */
*p*/
, const char */
*s*/
, unsigned /*f*/);
129 /* --- @str_match@ --- *
131 * Arguments: @const char *p@ = pointer to pattern string
132 * @const char *s@ = string to compare with
134 * Returns: Nonzero if the pattern matches the string.
136 * Use: Does simple wildcard matching. Equivalent to @str_matchx@
137 * with zero flags word.
140 extern int str_match(const char */
*p*/
, const char */
*s*/
);
142 /* --- @str_sanitize@ --- *
144 * Arguments: @char *d@ = destination buffer
145 * @const char *p@ = pointer to source string
146 * @size_t sz@ = size of destination buffer
150 * Use: Writes a string into a buffer, being careful not to overflow
151 * the buffer, to null terminate the result, and to prevent
152 * nasty nonprintable characters ending up in the buffer.
155 extern void str_sanitize(char */
*d*/
, const char */
*p*/
, size_t /*sz*/);
157 /*----- That's all, folks -------------------------------------------------*/