2 * Copyright (c) 2013, Olivier MATZ <zer0@droids-corp.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the University of California, Berkeley nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * String-related tools
37 * Append a formatted string in an allocated buffer
39 * This function acts as a asprintf, with some differences:
40 * - *but can already contain a string, in this case, the new string
42 * - *strp is set to NULL on error, like in BSD's asprintf
45 * Pointer to a (char *), must not be NULL. If *strp is NULL a new
46 * buffer is allocated to store the string. Else, if *strp is not
47 * NULL, it must point to a valid string in a buffer that was
48 * previously allocated using malloc.
50 * Format string, followed by other arguments, like in printf
52 * The number of bytes printed. If memory allocation wasn't
53 * possible, or some other error occurs, these functions will return
54 * -1, and the contents of strp is set to NULL.
56 int cfzy_string_asprintf(char **buf, const char *fmt, ...);
59 * Remove quotes on a string
61 * If the buffer is surrounded by quotes (simple or double), this
62 * function will allocate a new string and remove the quotes properly,
63 * also deleting the backslash in occurences of \\, \" or \'. If the
64 * buffer does not start by a quote, the function just return a
65 * duplicate of the input string.
67 * On sucess, the value pointer by eatlen is updated to the len of
68 * consumed bytes in the input buffer, including quotes if any, but
69 * not including \0. On error *eatlen is undefined.
74 * pointer to an int where the number of consumed bytes is written
76 * the unquoted string (allocated), or NULL on error
78 char *cfzy_string_unquote(const char *buf, unsigned *eatlen);
81 * Quote a string with double quotes
83 * Allocate a new string which is a copy of the first one, surrounded
84 * by quotes and quotes of initial string are escaped with a
90 * the quoted string (allocated), or NULL on error
92 char *cfzy_string_quote(const char *src);
94 #endif /* CFZY_STRING */