]> git.sesse.net Git - casparcg/blob - dependencies/ffmpeg 0.8/include/libavutil/avstring.h
Subtree merge of old SVN "dependencies" folder into the "master" git branch. You...
[casparcg] / dependencies / ffmpeg 0.8 / include / libavutil / avstring.h
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>
25 #include "attributes.h"
26
27 /**
28  * Return non-zero if pfx is a prefix of str. If it is, *ptr is set to
29  * the address of the first character in str after the prefix.
30  *
31  * @param str input string
32  * @param pfx prefix to test
33  * @param ptr updated if the prefix is matched inside str
34  * @return non-zero if the prefix matches, zero otherwise
35  */
36 int av_strstart(const char *str, const char *pfx, const char **ptr);
37
38 /**
39  * Return non-zero if pfx is a prefix of str independent of case. If
40  * it is, *ptr is set to the address of the first character in str
41  * after the prefix.
42  *
43  * @param str input string
44  * @param pfx prefix to test
45  * @param ptr updated if the prefix is matched inside str
46  * @return non-zero if the prefix matches, zero otherwise
47  */
48 int av_stristart(const char *str, const char *pfx, const char **ptr);
49
50 /**
51  * Locate the first case-independent occurrence in the string haystack
52  * of the string needle.  A zero-length string needle is considered to
53  * match at the start of haystack.
54  *
55  * This function is a case-insensitive version of the standard strstr().
56  *
57  * @param haystack string to search in
58  * @param needle   string to search for
59  * @return         pointer to the located match within haystack
60  *                 or a null pointer if no match
61  */
62 char *av_stristr(const char *haystack, const char *needle);
63
64 /**
65  * Copy the string src to dst, but no more than size - 1 bytes, and
66  * null-terminate dst.
67  *
68  * This function is the same as BSD strlcpy().
69  *
70  * @param dst destination buffer
71  * @param src source string
72  * @param size size of destination buffer
73  * @return the length of src
74  *
75  * WARNING: since the return value is the length of src, src absolutely
76  * _must_ be a properly 0-terminated string, otherwise this will read beyond
77  * the end of the buffer and possibly crash.
78  */
79 size_t av_strlcpy(char *dst, const char *src, size_t size);
80
81 /**
82  * Append the string src to the string dst, but to a total length of
83  * no more than size - 1 bytes, and null-terminate dst.
84  *
85  * This function is similar to BSD strlcat(), but differs when
86  * size <= strlen(dst).
87  *
88  * @param dst destination buffer
89  * @param src source string
90  * @param size size of destination buffer
91  * @return the total length of src and dst
92  *
93  * WARNING: since the return value use the length of src and dst, these absolutely
94  * _must_ be a properly 0-terminated strings, otherwise this will read beyond
95  * the end of the buffer and possibly crash.
96  */
97 size_t av_strlcat(char *dst, const char *src, size_t size);
98
99 /**
100  * Append output to a string, according to a format. Never write out of
101  * the destination buffer, and always put a terminating 0 within
102  * the buffer.
103  * @param dst destination buffer (string to which the output is
104  *  appended)
105  * @param size total size of the destination buffer
106  * @param fmt printf-compatible format string, specifying how the
107  *  following parameters are used
108  * @return the length of the string that would have been generated
109  *  if enough space had been available
110  */
111 size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...) av_printf_format(3, 4);
112
113 /**
114  * Print arguments following specified format into a large enough auto
115  * allocated buffer. It is similar to GNU asprintf().
116  * @param fmt printf-compatible format string, specifying how the
117  *            following parameters are used.
118  * @return the allocated string
119  * @note You have to free the string yourself with av_free().
120  */
121 char *av_asprintf(const char *fmt, ...) av_printf_format(1, 2);
122
123 /**
124  * Convert a number to a av_malloced string.
125  */
126 char *av_d2str(double d);
127
128 /**
129  * Unescape the given string until a non escaped terminating char,
130  * and return the token corresponding to the unescaped string.
131  *
132  * The normal \ and ' escaping is supported. Leading and trailing
133  * whitespaces are removed, unless they are escaped with '\' or are
134  * enclosed between ''.
135  *
136  * @param buf the buffer to parse, buf will be updated to point to the
137  * terminating char
138  * @param term a 0-terminated list of terminating chars
139  * @return the malloced unescaped string, which must be av_freed by
140  * the user, NULL in case of allocation failure
141  */
142 char *av_get_token(const char **buf, const char *term);
143
144 /**
145  * Split the string into several tokens which can be accessed by
146  * successive calls to av_strtok().
147  *
148  * A token is defined as a sequence of characters not belonging to the
149  * set specified in delim.
150  *
151  * On the first call to av_strtok(), s should point to the string to
152  * parse, and the value of saveptr is ignored. In subsequent calls, s
153  * should be NULL, and saveptr should be unchanged since the previous
154  * call.
155  *
156  * This function is similar to strtok_r() defined in POSIX.1.
157  *
158  * @param s the string to parse, may be NULL
159  * @param delim 0-terminated list of token delimiters, must be non-NULL
160  * @param saveptr user-provided pointer which points to stored
161  * information necessary for av_strtok() to continue scanning the same
162  * string. saveptr is updated to point to the next character after the
163  * first delimiter found, or to NULL if the string was terminated
164  * @return the found token, or NULL when no token is found
165  */
166 char *av_strtok(char *s, const char *delim, char **saveptr);
167
168 /**
169  * Locale independent conversion of ASCII characters to upper case.
170  */
171 static inline int av_toupper(int c)
172 {
173     if (c >= 'a' && c <= 'z')
174         c ^= 0x20;
175     return c;
176 }
177
178 /**
179  * Locale independent conversion of ASCII characters to lower case.
180  */
181 static inline int av_tolower(int c)
182 {
183     if (c >= 'A' && c <= 'Z')
184         c ^= 0x20;
185     return c;
186 }
187
188 /**
189  * Locale independent case-insensitive compare.
190  * Note: This means only ASCII-range characters are case-insensitive
191  */
192 int av_strcasecmp(const char *a, const char *b);
193
194 /**
195  * Locale independent case-insensitive compare.
196  * Note: This means only ASCII-range characters are case-insensitive
197  */
198 int av_strncasecmp(const char *a, const char *b, size_t n);
199
200 #endif /* AVUTIL_AVSTRING_H */