X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavutil%2Favstring.h;h=7c30ee18c608b9191660c6a282fc7b921e675c54;hb=f42485dbce614b3f63182845da43db690b427b7c;hp=87d29e3e0f238e46592a1a148763edee8a4deecd;hpb=89c9ff504b29d03cf266aa3598ccb8d2cf1ddd13;p=ffmpeg diff --git a/libavutil/avstring.h b/libavutil/avstring.h index 87d29e3e0f2..7c30ee18c60 100644 --- a/libavutil/avstring.h +++ b/libavutil/avstring.h @@ -1,20 +1,20 @@ /* * Copyright (c) 2007 Mans Rullgard * - * This file is part of FFmpeg. + * This file is part of Libav. * - * FFmpeg is free software; you can redistribute it and/or + * Libav is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * FFmpeg is distributed in the hope that it will be useful, + * Libav is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software + * License along with Libav; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -22,6 +22,12 @@ #define AVUTIL_AVSTRING_H #include +#include "attributes.h" + +/** + * @addtogroup lavu_string + * @{ + */ /** * Return non-zero if pfx is a prefix of str. If it is, *ptr is set to @@ -29,7 +35,7 @@ * * @param str input string * @param pfx prefix to test - * @param ptr updated after the prefix in str in there is a match + * @param ptr updated if the prefix is matched inside str * @return non-zero if the prefix matches, zero otherwise */ int av_strstart(const char *str, const char *pfx, const char **ptr); @@ -41,11 +47,40 @@ int av_strstart(const char *str, const char *pfx, const char **ptr); * * @param str input string * @param pfx prefix to test - * @param ptr updated after the prefix in str in there is a match + * @param ptr updated if the prefix is matched inside str * @return non-zero if the prefix matches, zero otherwise */ int av_stristart(const char *str, const char *pfx, const char **ptr); +/** + * Locate the first case-independent occurrence in the string haystack + * of the string needle. A zero-length string needle is considered to + * match at the start of haystack. + * + * This function is a case-insensitive version of the standard strstr(). + * + * @param haystack string to search in + * @param needle string to search for + * @return pointer to the located match within haystack + * or a null pointer if no match + */ +char *av_stristr(const char *haystack, const char *needle); + +/** + * Locate the first occurrence of the string needle in the string haystack + * where not more than hay_length characters are searched. A zero-length + * string needle is considered to match at the start of haystack. + * + * This function is a length-limited version of the standard strstr(). + * + * @param haystack string to search in + * @param needle string to search for + * @param hay_length length of string to search in + * @return pointer to the located match within haystack + * or a null pointer if no match + */ +char *av_strnstr(const char *haystack, const char *needle, size_t hay_length); + /** * Copy the string src to dst, but no more than size - 1 bytes, and * null-terminate dst. @@ -56,6 +91,10 @@ int av_stristart(const char *str, const char *pfx, const char **ptr); * @param src source string * @param size size of destination buffer * @return the length of src + * + * @warning since the return value is the length of src, src absolutely + * _must_ be a properly 0-terminated string, otherwise this will read beyond + * the end of the buffer and possibly crash. */ size_t av_strlcpy(char *dst, const char *src, size_t size); @@ -70,12 +109,16 @@ size_t av_strlcpy(char *dst, const char *src, size_t size); * @param src source string * @param size size of destination buffer * @return the total length of src and dst + * + * @warning since the return value use the length of src and dst, these + * absolutely _must_ be a properly 0-terminated strings, otherwise this + * will read beyond the end of the buffer and possibly crash. */ size_t av_strlcat(char *dst, const char *src, size_t size); /** * Append output to a string, according to a format. Never write out of - * the destination buffer, and and always put a terminating 0 within + * the destination buffer, and always put a terminating 0 within * the buffer. * @param dst destination buffer (string to which the output is * appended) @@ -85,6 +128,108 @@ size_t av_strlcat(char *dst, const char *src, size_t size); * @return the length of the string that would have been generated * if enough space had been available */ -size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...); +size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...) av_printf_format(3, 4); + +/** + * Convert a number to a av_malloced string. + */ +char *av_d2str(double d); + +/** + * Unescape the given string until a non escaped terminating char, + * and return the token corresponding to the unescaped string. + * + * The normal \ and ' escaping is supported. Leading and trailing + * whitespaces are removed, unless they are escaped with '\' or are + * enclosed between ''. + * + * @param buf the buffer to parse, buf will be updated to point to the + * terminating char + * @param term a 0-terminated list of terminating chars + * @return the malloced unescaped string, which must be av_freed by + * the user, NULL in case of allocation failure + */ +char *av_get_token(const char **buf, const char *term); + +/** + * Locale-independent conversion of ASCII isdigit. + */ +av_const int av_isdigit(int c); + +/** + * Locale-independent conversion of ASCII isgraph. + */ +av_const int av_isgraph(int c); + +/** + * Locale-independent conversion of ASCII isspace. + */ +av_const int av_isspace(int c); + +/** + * Locale-independent conversion of ASCII characters to uppercase. + */ +static inline av_const int av_toupper(int c) +{ + if (c >= 'a' && c <= 'z') + c ^= 0x20; + return c; +} + +/** + * Locale-independent conversion of ASCII characters to lowercase. + */ +static inline av_const int av_tolower(int c) +{ + if (c >= 'A' && c <= 'Z') + c ^= 0x20; + return c; +} + +/** + * Locale-independent conversion of ASCII isxdigit. + */ +av_const int av_isxdigit(int c); + +/* + * Locale-independent case-insensitive compare. + * @note This means only ASCII-range characters are case-insensitive + */ +int av_strcasecmp(const char *a, const char *b); + +/** + * Locale-independent case-insensitive compare. + * @note This means only ASCII-range characters are case-insensitive + */ +int av_strncasecmp(const char *a, const char *b, size_t n); + + +/** + * Thread safe basename. + * @param path the path, on DOS both \ and / are considered separators. + * @return pointer to the basename substring. + */ +const char *av_basename(const char *path); + +/** + * Thread safe dirname. + * @param path the path, on DOS both \ and / are considered separators. + * @return the path with the separator replaced by the string terminator or ".". + * @note the function may change the input string. + */ +const char *av_dirname(char *path); + + +/** + * Match instances of a name in a comma-separated list of names. + * @param name Name to look for. + * @param names List of names. + * @return 1 on match, 0 otherwise. + */ +int av_match_name(const char *name, const char *names); + +/** + * @} + */ #endif /* AVUTIL_AVSTRING_H */