annotate ffmpeg/libavutil/avstring.h @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * Copyright (c) 2007 Mans Rullgard
yading@11 3 *
yading@11 4 * This file is part of FFmpeg.
yading@11 5 *
yading@11 6 * FFmpeg is free software; you can redistribute it and/or
yading@11 7 * modify it under the terms of the GNU Lesser General Public
yading@11 8 * License as published by the Free Software Foundation; either
yading@11 9 * version 2.1 of the License, or (at your option) any later version.
yading@11 10 *
yading@11 11 * FFmpeg is distributed in the hope that it will be useful,
yading@11 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 14 * Lesser General Public License for more details.
yading@11 15 *
yading@11 16 * You should have received a copy of the GNU Lesser General Public
yading@11 17 * License along with FFmpeg; if not, write to the Free Software
yading@11 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 19 */
yading@11 20
yading@11 21 #ifndef AVUTIL_AVSTRING_H
yading@11 22 #define AVUTIL_AVSTRING_H
yading@11 23
yading@11 24 #include <stddef.h>
yading@11 25 #include "attributes.h"
yading@11 26
yading@11 27 /**
yading@11 28 * @addtogroup lavu_string
yading@11 29 * @{
yading@11 30 */
yading@11 31
yading@11 32 /**
yading@11 33 * Return non-zero if pfx is a prefix of str. If it is, *ptr is set to
yading@11 34 * the address of the first character in str after the prefix.
yading@11 35 *
yading@11 36 * @param str input string
yading@11 37 * @param pfx prefix to test
yading@11 38 * @param ptr updated if the prefix is matched inside str
yading@11 39 * @return non-zero if the prefix matches, zero otherwise
yading@11 40 */
yading@11 41 int av_strstart(const char *str, const char *pfx, const char **ptr);
yading@11 42
yading@11 43 /**
yading@11 44 * Return non-zero if pfx is a prefix of str independent of case. If
yading@11 45 * it is, *ptr is set to the address of the first character in str
yading@11 46 * after the prefix.
yading@11 47 *
yading@11 48 * @param str input string
yading@11 49 * @param pfx prefix to test
yading@11 50 * @param ptr updated if the prefix is matched inside str
yading@11 51 * @return non-zero if the prefix matches, zero otherwise
yading@11 52 */
yading@11 53 int av_stristart(const char *str, const char *pfx, const char **ptr);
yading@11 54
yading@11 55 /**
yading@11 56 * Locate the first case-independent occurrence in the string haystack
yading@11 57 * of the string needle. A zero-length string needle is considered to
yading@11 58 * match at the start of haystack.
yading@11 59 *
yading@11 60 * This function is a case-insensitive version of the standard strstr().
yading@11 61 *
yading@11 62 * @param haystack string to search in
yading@11 63 * @param needle string to search for
yading@11 64 * @return pointer to the located match within haystack
yading@11 65 * or a null pointer if no match
yading@11 66 */
yading@11 67 char *av_stristr(const char *haystack, const char *needle);
yading@11 68
yading@11 69 /**
yading@11 70 * Locate the first occurrence of the string needle in the string haystack
yading@11 71 * where not more than hay_length characters are searched. A zero-length
yading@11 72 * string needle is considered to match at the start of haystack.
yading@11 73 *
yading@11 74 * This function is a length-limited version of the standard strstr().
yading@11 75 *
yading@11 76 * @param haystack string to search in
yading@11 77 * @param needle string to search for
yading@11 78 * @param hay_length length of string to search in
yading@11 79 * @return pointer to the located match within haystack
yading@11 80 * or a null pointer if no match
yading@11 81 */
yading@11 82 char *av_strnstr(const char *haystack, const char *needle, size_t hay_length);
yading@11 83
yading@11 84 /**
yading@11 85 * Copy the string src to dst, but no more than size - 1 bytes, and
yading@11 86 * null-terminate dst.
yading@11 87 *
yading@11 88 * This function is the same as BSD strlcpy().
yading@11 89 *
yading@11 90 * @param dst destination buffer
yading@11 91 * @param src source string
yading@11 92 * @param size size of destination buffer
yading@11 93 * @return the length of src
yading@11 94 *
yading@11 95 * @warning since the return value is the length of src, src absolutely
yading@11 96 * _must_ be a properly 0-terminated string, otherwise this will read beyond
yading@11 97 * the end of the buffer and possibly crash.
yading@11 98 */
yading@11 99 size_t av_strlcpy(char *dst, const char *src, size_t size);
yading@11 100
yading@11 101 /**
yading@11 102 * Append the string src to the string dst, but to a total length of
yading@11 103 * no more than size - 1 bytes, and null-terminate dst.
yading@11 104 *
yading@11 105 * This function is similar to BSD strlcat(), but differs when
yading@11 106 * size <= strlen(dst).
yading@11 107 *
yading@11 108 * @param dst destination buffer
yading@11 109 * @param src source string
yading@11 110 * @param size size of destination buffer
yading@11 111 * @return the total length of src and dst
yading@11 112 *
yading@11 113 * @warning since the return value use the length of src and dst, these
yading@11 114 * absolutely _must_ be a properly 0-terminated strings, otherwise this
yading@11 115 * will read beyond the end of the buffer and possibly crash.
yading@11 116 */
yading@11 117 size_t av_strlcat(char *dst, const char *src, size_t size);
yading@11 118
yading@11 119 /**
yading@11 120 * Append output to a string, according to a format. Never write out of
yading@11 121 * the destination buffer, and always put a terminating 0 within
yading@11 122 * the buffer.
yading@11 123 * @param dst destination buffer (string to which the output is
yading@11 124 * appended)
yading@11 125 * @param size total size of the destination buffer
yading@11 126 * @param fmt printf-compatible format string, specifying how the
yading@11 127 * following parameters are used
yading@11 128 * @return the length of the string that would have been generated
yading@11 129 * if enough space had been available
yading@11 130 */
yading@11 131 size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...) av_printf_format(3, 4);
yading@11 132
yading@11 133 /**
yading@11 134 * Print arguments following specified format into a large enough auto
yading@11 135 * allocated buffer. It is similar to GNU asprintf().
yading@11 136 * @param fmt printf-compatible format string, specifying how the
yading@11 137 * following parameters are used.
yading@11 138 * @return the allocated string
yading@11 139 * @note You have to free the string yourself with av_free().
yading@11 140 */
yading@11 141 char *av_asprintf(const char *fmt, ...) av_printf_format(1, 2);
yading@11 142
yading@11 143 /**
yading@11 144 * Convert a number to a av_malloced string.
yading@11 145 */
yading@11 146 char *av_d2str(double d);
yading@11 147
yading@11 148 /**
yading@11 149 * Unescape the given string until a non escaped terminating char,
yading@11 150 * and return the token corresponding to the unescaped string.
yading@11 151 *
yading@11 152 * The normal \ and ' escaping is supported. Leading and trailing
yading@11 153 * whitespaces are removed, unless they are escaped with '\' or are
yading@11 154 * enclosed between ''.
yading@11 155 *
yading@11 156 * @param buf the buffer to parse, buf will be updated to point to the
yading@11 157 * terminating char
yading@11 158 * @param term a 0-terminated list of terminating chars
yading@11 159 * @return the malloced unescaped string, which must be av_freed by
yading@11 160 * the user, NULL in case of allocation failure
yading@11 161 */
yading@11 162 char *av_get_token(const char **buf, const char *term);
yading@11 163
yading@11 164 /**
yading@11 165 * Split the string into several tokens which can be accessed by
yading@11 166 * successive calls to av_strtok().
yading@11 167 *
yading@11 168 * A token is defined as a sequence of characters not belonging to the
yading@11 169 * set specified in delim.
yading@11 170 *
yading@11 171 * On the first call to av_strtok(), s should point to the string to
yading@11 172 * parse, and the value of saveptr is ignored. In subsequent calls, s
yading@11 173 * should be NULL, and saveptr should be unchanged since the previous
yading@11 174 * call.
yading@11 175 *
yading@11 176 * This function is similar to strtok_r() defined in POSIX.1.
yading@11 177 *
yading@11 178 * @param s the string to parse, may be NULL
yading@11 179 * @param delim 0-terminated list of token delimiters, must be non-NULL
yading@11 180 * @param saveptr user-provided pointer which points to stored
yading@11 181 * information necessary for av_strtok() to continue scanning the same
yading@11 182 * string. saveptr is updated to point to the next character after the
yading@11 183 * first delimiter found, or to NULL if the string was terminated
yading@11 184 * @return the found token, or NULL when no token is found
yading@11 185 */
yading@11 186 char *av_strtok(char *s, const char *delim, char **saveptr);
yading@11 187
yading@11 188 /**
yading@11 189 * Locale-independent conversion of ASCII isdigit.
yading@11 190 */
yading@11 191 int av_isdigit(int c);
yading@11 192
yading@11 193 /**
yading@11 194 * Locale-independent conversion of ASCII isgraph.
yading@11 195 */
yading@11 196 int av_isgraph(int c);
yading@11 197
yading@11 198 /**
yading@11 199 * Locale-independent conversion of ASCII isspace.
yading@11 200 */
yading@11 201 int av_isspace(int c);
yading@11 202
yading@11 203 /**
yading@11 204 * Locale-independent conversion of ASCII characters to uppercase.
yading@11 205 */
yading@11 206 static inline int av_toupper(int c)
yading@11 207 {
yading@11 208 if (c >= 'a' && c <= 'z')
yading@11 209 c ^= 0x20;
yading@11 210 return c;
yading@11 211 }
yading@11 212
yading@11 213 /**
yading@11 214 * Locale-independent conversion of ASCII characters to lowercase.
yading@11 215 */
yading@11 216 static inline int av_tolower(int c)
yading@11 217 {
yading@11 218 if (c >= 'A' && c <= 'Z')
yading@11 219 c ^= 0x20;
yading@11 220 return c;
yading@11 221 }
yading@11 222
yading@11 223 /**
yading@11 224 * Locale-independent conversion of ASCII isxdigit.
yading@11 225 */
yading@11 226 int av_isxdigit(int c);
yading@11 227
yading@11 228 /**
yading@11 229 * Locale-independent case-insensitive compare.
yading@11 230 * @note This means only ASCII-range characters are case-insensitive
yading@11 231 */
yading@11 232 int av_strcasecmp(const char *a, const char *b);
yading@11 233
yading@11 234 /**
yading@11 235 * Locale-independent case-insensitive compare.
yading@11 236 * @note This means only ASCII-range characters are case-insensitive
yading@11 237 */
yading@11 238 int av_strncasecmp(const char *a, const char *b, size_t n);
yading@11 239
yading@11 240
yading@11 241 /**
yading@11 242 * Thread safe basename.
yading@11 243 * @param path the path, on DOS both \ and / are considered separators.
yading@11 244 * @return pointer to the basename substring.
yading@11 245 */
yading@11 246 const char *av_basename(const char *path);
yading@11 247
yading@11 248 /**
yading@11 249 * Thread safe dirname.
yading@11 250 * @param path the path, on DOS both \ and / are considered separators.
yading@11 251 * @return the path with the separator replaced by the string terminator or ".".
yading@11 252 * @note the function may change the input string.
yading@11 253 */
yading@11 254 const char *av_dirname(char *path);
yading@11 255
yading@11 256 enum AVEscapeMode {
yading@11 257 AV_ESCAPE_MODE_AUTO, ///< Use auto-selected escaping mode.
yading@11 258 AV_ESCAPE_MODE_BACKSLASH, ///< Use backslash escaping.
yading@11 259 AV_ESCAPE_MODE_QUOTE, ///< Use single-quote escaping.
yading@11 260 };
yading@11 261
yading@11 262 /**
yading@11 263 * Consider spaces special and escape them even in the middle of the
yading@11 264 * string.
yading@11 265 *
yading@11 266 * This is equivalent to adding the whitespace characters to the special
yading@11 267 * characters lists, except it is guaranteed to use the exact same list
yading@11 268 * of whitespace characters as the rest of libavutil.
yading@11 269 */
yading@11 270 #define AV_ESCAPE_FLAG_WHITESPACE 0x01
yading@11 271
yading@11 272 /**
yading@11 273 * Escape only specified special characters.
yading@11 274 * Without this flag, escape also any characters that may be considered
yading@11 275 * special by av_get_token(), such as the single quote.
yading@11 276 */
yading@11 277 #define AV_ESCAPE_FLAG_STRICT 0x02
yading@11 278
yading@11 279 /**
yading@11 280 * Escape string in src, and put the escaped string in an allocated
yading@11 281 * string in *dst, which must be freed with av_free().
yading@11 282 *
yading@11 283 * @param dst pointer where an allocated string is put
yading@11 284 * @param src string to escape, must be non-NULL
yading@11 285 * @param special_chars string containing the special characters which
yading@11 286 * need to be escaped, can be NULL
yading@11 287 * @param mode escape mode to employ, see AV_ESCAPE_MODE_* macros.
yading@11 288 * Any unknown value for mode will be considered equivalent to
yading@11 289 * AV_ESCAPE_MODE_BACKSLASH, but this behaviour can change without
yading@11 290 * notice.
yading@11 291 * @param flags flags which control how to escape, see AV_ESCAPE_FLAG_ macros
yading@11 292 * @return the length of the allocated string, or a negative error code in case of error
yading@11 293 * @see av_bprint_escape()
yading@11 294 */
yading@11 295 int av_escape(char **dst, const char *src, const char *special_chars,
yading@11 296 enum AVEscapeMode mode, int flags);
yading@11 297
yading@11 298 /**
yading@11 299 * @}
yading@11 300 */
yading@11 301
yading@11 302 #endif /* AVUTIL_AVSTRING_H */