2007-06-23 23:10:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Mans Rullgard
|
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* This file is part of Libav.
|
2007-06-23 23:10:26 +00:00
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2007-06-23 23:10:26 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2007-06-23 23:10:26 +00:00
|
|
|
* 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
|
2011-03-18 17:35:10 +00:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2007-06-23 23:10:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2008-08-31 07:39:47 +00:00
|
|
|
#ifndef AVUTIL_AVSTRING_H
|
|
|
|
#define AVUTIL_AVSTRING_H
|
2007-06-23 23:10:26 +00:00
|
|
|
|
|
|
|
#include <stddef.h>
|
2011-06-17 07:31:11 +00:00
|
|
|
#include "attributes.h"
|
2007-06-23 23:10:26 +00:00
|
|
|
|
2011-11-20 19:38:24 +00:00
|
|
|
/**
|
|
|
|
* @addtogroup lavu_string
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2007-06-23 23:10:26 +00:00
|
|
|
/**
|
|
|
|
* Return non-zero if pfx is a prefix of str. If it is, *ptr is set to
|
|
|
|
* the address of the first character in str after the prefix.
|
|
|
|
*
|
|
|
|
* @param str input string
|
|
|
|
* @param pfx prefix to test
|
2009-01-28 23:16:49 +00:00
|
|
|
* @param ptr updated if the prefix is matched inside str
|
2007-06-23 23:10:26 +00:00
|
|
|
* @return non-zero if the prefix matches, zero otherwise
|
|
|
|
*/
|
|
|
|
int av_strstart(const char *str, const char *pfx, const char **ptr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return non-zero if pfx is a prefix of str independent of case. If
|
|
|
|
* it is, *ptr is set to the address of the first character in str
|
|
|
|
* after the prefix.
|
|
|
|
*
|
|
|
|
* @param str input string
|
|
|
|
* @param pfx prefix to test
|
2009-01-28 23:16:49 +00:00
|
|
|
* @param ptr updated if the prefix is matched inside str
|
2007-06-23 23:10:26 +00:00
|
|
|
* @return non-zero if the prefix matches, zero otherwise
|
|
|
|
*/
|
|
|
|
int av_stristart(const char *str, const char *pfx, const char **ptr);
|
|
|
|
|
2010-03-06 19:41:22 +00:00
|
|
|
/**
|
2010-03-08 22:16:05 +00:00
|
|
|
* 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.
|
2010-03-06 19:41:22 +00:00
|
|
|
*
|
|
|
|
* This function is a case-insensitive version of the standard strstr().
|
|
|
|
*
|
2010-03-08 22:16:05 +00:00
|
|
|
* @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
|
2010-03-06 19:41:22 +00:00
|
|
|
*/
|
2010-03-08 22:16:05 +00:00
|
|
|
char *av_stristr(const char *haystack, const char *needle);
|
2010-03-06 19:41:22 +00:00
|
|
|
|
2013-01-24 14:09:48 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2007-06-23 23:10:26 +00:00
|
|
|
/**
|
|
|
|
* Copy the string src to dst, but no more than size - 1 bytes, and
|
2009-01-28 00:16:05 +00:00
|
|
|
* null-terminate dst.
|
2007-06-23 23:10:26 +00:00
|
|
|
*
|
|
|
|
* This function is the same as BSD strlcpy().
|
|
|
|
*
|
|
|
|
* @param dst destination buffer
|
|
|
|
* @param src source string
|
|
|
|
* @param size size of destination buffer
|
|
|
|
* @return the length of src
|
2009-09-09 21:00:51 +00:00
|
|
|
*
|
2011-11-20 19:38:24 +00:00
|
|
|
* @warning since the return value is the length of src, src absolutely
|
2009-09-09 21:00:51 +00:00
|
|
|
* _must_ be a properly 0-terminated string, otherwise this will read beyond
|
|
|
|
* the end of the buffer and possibly crash.
|
2007-06-23 23:10:26 +00:00
|
|
|
*/
|
|
|
|
size_t av_strlcpy(char *dst, const char *src, size_t size);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Append the string src to the string dst, but to a total length of
|
2009-01-28 00:16:05 +00:00
|
|
|
* no more than size - 1 bytes, and null-terminate dst.
|
2007-06-23 23:10:26 +00:00
|
|
|
*
|
|
|
|
* This function is similar to BSD strlcat(), but differs when
|
|
|
|
* size <= strlen(dst).
|
|
|
|
*
|
|
|
|
* @param dst destination buffer
|
|
|
|
* @param src source string
|
|
|
|
* @param size size of destination buffer
|
|
|
|
* @return the total length of src and dst
|
2009-09-09 21:00:51 +00:00
|
|
|
*
|
2011-11-20 19:38:24 +00:00
|
|
|
* @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.
|
2007-06-23 23:10:26 +00:00
|
|
|
*/
|
|
|
|
size_t av_strlcat(char *dst, const char *src, size_t size);
|
|
|
|
|
2007-07-19 06:36:02 +00:00
|
|
|
/**
|
|
|
|
* Append output to a string, according to a format. Never write out of
|
2010-01-30 19:03:37 +00:00
|
|
|
* the destination buffer, and always put a terminating 0 within
|
2007-07-19 06:36:02 +00:00
|
|
|
* the buffer.
|
|
|
|
* @param dst destination buffer (string to which the output is
|
|
|
|
* appended)
|
|
|
|
* @param size total size of the destination buffer
|
|
|
|
* @param fmt printf-compatible format string, specifying how the
|
|
|
|
* following parameters are used
|
|
|
|
* @return the length of the string that would have been generated
|
|
|
|
* if enough space had been available
|
|
|
|
*/
|
2011-06-17 07:31:11 +00:00
|
|
|
size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...) av_printf_format(3, 4);
|
2007-07-19 06:36:02 +00:00
|
|
|
|
2009-12-13 17:09:41 +00:00
|
|
|
/**
|
|
|
|
* Convert a number to a av_malloced string.
|
|
|
|
*/
|
|
|
|
char *av_d2str(double d);
|
|
|
|
|
2010-09-27 16:23:43 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2013-03-06 12:00:22 +00:00
|
|
|
/**
|
|
|
|
* Locale-independent conversion of ASCII isdigit.
|
|
|
|
*/
|
2015-09-26 20:27:36 +00:00
|
|
|
static inline av_const int av_isdigit(int c)
|
|
|
|
{
|
|
|
|
return c >= '0' && c <= '9';
|
|
|
|
}
|
2013-03-06 12:00:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Locale-independent conversion of ASCII isgraph.
|
|
|
|
*/
|
2015-09-26 20:27:36 +00:00
|
|
|
static inline av_const int av_isgraph(int c)
|
|
|
|
{
|
|
|
|
return c > 32 && c < 127;
|
|
|
|
}
|
2013-03-06 12:00:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Locale-independent conversion of ASCII isspace.
|
|
|
|
*/
|
2015-09-26 20:27:36 +00:00
|
|
|
static inline av_const int av_isspace(int c)
|
|
|
|
{
|
|
|
|
return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' ||
|
|
|
|
c == '\v';
|
|
|
|
}
|
2013-03-06 12:00:22 +00:00
|
|
|
|
2011-11-05 15:15:43 +00:00
|
|
|
/**
|
2011-12-07 12:03:53 +00:00
|
|
|
* Locale-independent conversion of ASCII characters to uppercase.
|
2011-11-05 15:15:43 +00:00
|
|
|
*/
|
2014-11-04 23:05:42 +00:00
|
|
|
static inline av_const int av_toupper(int c)
|
2011-11-05 15:15:43 +00:00
|
|
|
{
|
|
|
|
if (c >= 'a' && c <= 'z')
|
|
|
|
c ^= 0x20;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-12-07 12:03:53 +00:00
|
|
|
* Locale-independent conversion of ASCII characters to lowercase.
|
2011-11-05 15:15:43 +00:00
|
|
|
*/
|
2014-11-04 23:05:42 +00:00
|
|
|
static inline av_const int av_tolower(int c)
|
2011-11-05 15:15:43 +00:00
|
|
|
{
|
|
|
|
if (c >= 'A' && c <= 'Z')
|
|
|
|
c ^= 0x20;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2013-03-06 12:00:22 +00:00
|
|
|
/**
|
|
|
|
* Locale-independent conversion of ASCII isxdigit.
|
|
|
|
*/
|
2015-09-26 20:27:36 +00:00
|
|
|
static inline av_const int av_isxdigit(int c)
|
|
|
|
{
|
|
|
|
c = av_tolower(c);
|
|
|
|
return av_isdigit(c) || (c >= 'a' && c <= 'f');
|
|
|
|
}
|
2013-03-06 12:00:22 +00:00
|
|
|
|
2011-11-05 15:20:41 +00:00
|
|
|
/*
|
2011-12-07 12:03:53 +00:00
|
|
|
* Locale-independent case-insensitive compare.
|
2011-11-20 19:38:24 +00:00
|
|
|
* @note This means only ASCII-range characters are case-insensitive
|
2011-11-05 15:20:41 +00:00
|
|
|
*/
|
|
|
|
int av_strcasecmp(const char *a, const char *b);
|
|
|
|
|
|
|
|
/**
|
2011-12-07 12:03:53 +00:00
|
|
|
* Locale-independent case-insensitive compare.
|
2011-11-20 19:38:24 +00:00
|
|
|
* @note This means only ASCII-range characters are case-insensitive
|
2011-11-05 15:20:41 +00:00
|
|
|
*/
|
|
|
|
int av_strncasecmp(const char *a, const char *b, size_t n);
|
|
|
|
|
2012-12-23 20:25:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2014-07-29 13:29:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2011-11-20 19:38:24 +00:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2008-08-31 07:39:47 +00:00
|
|
|
#endif /* AVUTIL_AVSTRING_H */
|