1 /*
2 * Copyright (c) 2007 Mans Rullgard
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef AVUTIL_AVSTRING_H
22 #define AVUTIL_AVSTRING_H
23
24 #include <stddef.h>
26
27 /**
28 * @addtogroup lavu_string
29 * @{
30 */
31
32 /**
33 * Return non-zero if pfx is a prefix of str. If it is, *ptr is set to
34 * the address of the first character in str after the prefix.
35 *
36 * @param str input string
37 * @param pfx prefix to test
38 * @param ptr updated if the prefix is matched inside str
39 * @return non-zero if the prefix matches, zero otherwise
40 */
41 int av_strstart(
const char *str,
const char *pfx,
const char **ptr);
42
43 /**
44 * Return non-zero if pfx is a prefix of str independent of case. If
45 * it is, *ptr is set to the address of the first character in str
46 * after the prefix.
47 *
48 * @param str input string
49 * @param pfx prefix to test
50 * @param ptr updated if the prefix is matched inside str
51 * @return non-zero if the prefix matches, zero otherwise
52 */
53 int av_stristart(
const char *str,
const char *pfx,
const char **ptr);
54
55 /**
56 * Locate the first case-independent occurrence in the string haystack
57 * of the string needle. A zero-length string needle is considered to
58 * match at the start of haystack.
59 *
60 * This function is a case-insensitive version of the standard strstr().
61 *
62 * @param haystack string to search in
63 * @param needle string to search for
64 * @return pointer to the located match within haystack
65 * or a null pointer if no match
66 */
67 char *
av_stristr(
const char *haystack,
const char *needle);
68
69 /**
70 * Copy the string src to dst, but no more than size - 1 bytes, and
71 * null-terminate dst.
72 *
73 * This function is the same as BSD strlcpy().
74 *
75 * @param dst destination buffer
76 * @param src source string
77 * @param size size of destination buffer
78 * @return the length of src
79 *
80 * @warning since the return value is the length of src, src absolutely
81 * _must_ be a properly 0-terminated string, otherwise this will read beyond
82 * the end of the buffer and possibly crash.
83 */
85
86 /**
87 * Append the string src to the string dst, but to a total length of
88 * no more than size - 1 bytes, and null-terminate dst.
89 *
90 * This function is similar to BSD strlcat(), but differs when
91 * size <= strlen(dst).
92 *
93 * @param dst destination buffer
94 * @param src source string
95 * @param size size of destination buffer
96 * @return the total length of src and dst
97 *
98 * @warning since the return value use the length of src and dst, these
99 * absolutely _must_ be a properly 0-terminated strings, otherwise this
100 * will read beyond the end of the buffer and possibly crash.
101 */
103
104 /**
105 * Append output to a string, according to a format. Never write out of
106 * the destination buffer, and always put a terminating 0 within
107 * the buffer.
108 * @param dst destination buffer (string to which the output is
109 * appended)
110 * @param size total size of the destination buffer
111 * @param fmt printf-compatible format string, specifying how the
112 * following parameters are used
113 * @return the length of the string that would have been generated
114 * if enough space had been available
115 */
117
118 /**
119 * Print arguments following specified format into a large enough auto
120 * allocated buffer. It is similar to GNU asprintf().
121 * @param fmt printf-compatible format string, specifying how the
122 * following parameters are used.
123 * @return the allocated string
124 * @note You have to free the string yourself with av_free().
125 */
127
128 /**
129 * Convert a number to a av_malloced string.
130 */
132
133 /**
134 * Unescape the given string until a non escaped terminating char,
135 * and return the token corresponding to the unescaped string.
136 *
137 * The normal \ and ' escaping is supported. Leading and trailing
138 * whitespaces are removed, unless they are escaped with '\' or are
139 * enclosed between ''.
140 *
141 * @param buf the buffer to parse, buf will be updated to point to the
142 * terminating char
143 * @param term a 0-terminated list of terminating chars
144 * @return the malloced unescaped string, which must be av_freed by
145 * the user, NULL in case of allocation failure
146 */
148
149 /**
150 * Split the string into several tokens which can be accessed by
151 * successive calls to av_strtok().
152 *
153 * A token is defined as a sequence of characters not belonging to the
154 * set specified in delim.
155 *
156 * On the first call to av_strtok(), s should point to the string to
157 * parse, and the value of saveptr is ignored. In subsequent calls, s
158 * should be NULL, and saveptr should be unchanged since the previous
159 * call.
160 *
161 * This function is similar to strtok_r() defined in POSIX.1.
162 *
163 * @param s the string to parse, may be NULL
164 * @param delim 0-terminated list of token delimiters, must be non-NULL
165 * @param saveptr user-provided pointer which points to stored
166 * information necessary for av_strtok() to continue scanning the same
167 * string. saveptr is updated to point to the next character after the
168 * first delimiter found, or to NULL if the string was terminated
169 * @return the found token, or NULL when no token is found
170 */
171 char *
av_strtok(
char *s, const
char *delim,
char **saveptr);
172
173 /**
174 * Locale-independent conversion of ASCII characters to uppercase.
175 */
177 {
178 if (c >= 'a' && c <= 'z')
179 c ^= 0x20;
181 }
182
183 /**
184 * Locale-independent conversion of ASCII characters to lowercase.
185 */
187 {
188 if (c >= 'A' && c <= 'Z')
189 c ^= 0x20;
191 }
192
193 /**
194 * Locale-independent case-insensitive compare.
195 * @note This means only ASCII-range characters are case-insensitive
196 */
198
199 /**
200 * Locale-independent case-insensitive compare.
201 * @note This means only ASCII-range characters are case-insensitive
202 */
204
205
206 /**
207 * Thread safe basename.
208 * @param path the path, on DOS both \ and / are considered separators.
209 * @return pointer to the basename substring.
210 */
212
213 /**
214 * Thread safe dirname.
215 * @param path the path, on DOS both \ and / are considered separators.
216 * @return the path with the separator replaced by the string terminator or ".".
217 * @note the function may change the input string.
218 */
220
221 /**
222 * @}
223 */
224
225 #endif /* AVUTIL_AVSTRING_H */