Path: blob/a-new-beginning/libavutil.xcframework/ios-arm64-simulator/libavutil.framework/Headers/avstring.h
2 views
/*1* Copyright (c) 2007 Mans Rullgard2*3* This file is part of FFmpeg.4*5* FFmpeg is free software; you can redistribute it and/or6* modify it under the terms of the GNU Lesser General Public7* License as published by the Free Software Foundation; either8* version 2.1 of the License, or (at your option) any later version.9*10* FFmpeg is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU13* Lesser General Public License for more details.14*15* You should have received a copy of the GNU Lesser General Public16* License along with FFmpeg; if not, write to the Free Software17* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA18*/1920#ifndef AVUTIL_AVSTRING_H21#define AVUTIL_AVSTRING_H2223#include <stddef.h>24#include <stdint.h>25#include "attributes.h"26#include "version.h"2728/**29* @addtogroup lavu_string30* @{31*/3233/**34* Return non-zero if pfx is a prefix of str. If it is, *ptr is set to35* the address of the first character in str after the prefix.36*37* @param str input string38* @param pfx prefix to test39* @param ptr updated if the prefix is matched inside str40* @return non-zero if the prefix matches, zero otherwise41*/42int av_strstart(const char *str, const char *pfx, const char **ptr);4344/**45* Return non-zero if pfx is a prefix of str independent of case. If46* it is, *ptr is set to the address of the first character in str47* after the prefix.48*49* @param str input string50* @param pfx prefix to test51* @param ptr updated if the prefix is matched inside str52* @return non-zero if the prefix matches, zero otherwise53*/54int av_stristart(const char *str, const char *pfx, const char **ptr);5556/**57* Locate the first case-independent occurrence in the string haystack58* of the string needle. A zero-length string needle is considered to59* match at the start of haystack.60*61* This function is a case-insensitive version of the standard strstr().62*63* @param haystack string to search in64* @param needle string to search for65* @return pointer to the located match within haystack66* or a null pointer if no match67*/68char *av_stristr(const char *haystack, const char *needle);6970/**71* Locate the first occurrence of the string needle in the string haystack72* where not more than hay_length characters are searched. A zero-length73* string needle is considered to match at the start of haystack.74*75* This function is a length-limited version of the standard strstr().76*77* @param haystack string to search in78* @param needle string to search for79* @param hay_length length of string to search in80* @return pointer to the located match within haystack81* or a null pointer if no match82*/83char *av_strnstr(const char *haystack, const char *needle, size_t hay_length);8485/**86* Copy the string src to dst, but no more than size - 1 bytes, and87* null-terminate dst.88*89* This function is the same as BSD strlcpy().90*91* @param dst destination buffer92* @param src source string93* @param size size of destination buffer94* @return the length of src95*96* @warning since the return value is the length of src, src absolutely97* _must_ be a properly 0-terminated string, otherwise this will read beyond98* the end of the buffer and possibly crash.99*/100size_t av_strlcpy(char *dst, const char *src, size_t size);101102/**103* Append the string src to the string dst, but to a total length of104* no more than size - 1 bytes, and null-terminate dst.105*106* This function is similar to BSD strlcat(), but differs when107* size <= strlen(dst).108*109* @param dst destination buffer110* @param src source string111* @param size size of destination buffer112* @return the total length of src and dst113*114* @warning since the return value use the length of src and dst, these115* absolutely _must_ be a properly 0-terminated strings, otherwise this116* will read beyond the end of the buffer and possibly crash.117*/118size_t av_strlcat(char *dst, const char *src, size_t size);119120/**121* Append output to a string, according to a format. Never write out of122* the destination buffer, and always put a terminating 0 within123* the buffer.124* @param dst destination buffer (string to which the output is125* appended)126* @param size total size of the destination buffer127* @param fmt printf-compatible format string, specifying how the128* following parameters are used129* @return the length of the string that would have been generated130* if enough space had been available131*/132size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...) av_printf_format(3, 4);133134/**135* Get the count of continuous non zero chars starting from the beginning.136*137* @param s the string whose length to count138* @param len maximum number of characters to check in the string, that139* is the maximum value which is returned by the function140*/141static inline size_t av_strnlen(const char *s, size_t len)142{143size_t i;144for (i = 0; i < len && s[i]; i++)145;146return i;147}148149/**150* Print arguments following specified format into a large enough auto151* allocated buffer. It is similar to GNU asprintf().152* @param fmt printf-compatible format string, specifying how the153* following parameters are used.154* @return the allocated string155* @note You have to free the string yourself with av_free().156*/157char *av_asprintf(const char *fmt, ...) av_printf_format(1, 2);158159/**160* Unescape the given string until a non escaped terminating char,161* and return the token corresponding to the unescaped string.162*163* The normal \ and ' escaping is supported. Leading and trailing164* whitespaces are removed, unless they are escaped with '\' or are165* enclosed between ''.166*167* @param buf the buffer to parse, buf will be updated to point to the168* terminating char169* @param term a 0-terminated list of terminating chars170* @return the malloced unescaped string, which must be av_freed by171* the user, NULL in case of allocation failure172*/173char *av_get_token(const char **buf, const char *term);174175/**176* Split the string into several tokens which can be accessed by177* successive calls to av_strtok().178*179* A token is defined as a sequence of characters not belonging to the180* set specified in delim.181*182* On the first call to av_strtok(), s should point to the string to183* parse, and the value of saveptr is ignored. In subsequent calls, s184* should be NULL, and saveptr should be unchanged since the previous185* call.186*187* This function is similar to strtok_r() defined in POSIX.1.188*189* @param s the string to parse, may be NULL190* @param delim 0-terminated list of token delimiters, must be non-NULL191* @param saveptr user-provided pointer which points to stored192* information necessary for av_strtok() to continue scanning the same193* string. saveptr is updated to point to the next character after the194* first delimiter found, or to NULL if the string was terminated195* @return the found token, or NULL when no token is found196*/197char *av_strtok(char *s, const char *delim, char **saveptr);198199/**200* Locale-independent conversion of ASCII isdigit.201*/202static inline av_const int av_isdigit(int c)203{204return c >= '0' && c <= '9';205}206207/**208* Locale-independent conversion of ASCII isgraph.209*/210static inline av_const int av_isgraph(int c)211{212return c > 32 && c < 127;213}214215/**216* Locale-independent conversion of ASCII isspace.217*/218static inline av_const int av_isspace(int c)219{220return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' ||221c == '\v';222}223224/**225* Locale-independent conversion of ASCII characters to uppercase.226*/227static inline av_const int av_toupper(int c)228{229if (c >= 'a' && c <= 'z')230c ^= 0x20;231return c;232}233234/**235* Locale-independent conversion of ASCII characters to lowercase.236*/237static inline av_const int av_tolower(int c)238{239if (c >= 'A' && c <= 'Z')240c ^= 0x20;241return c;242}243244/**245* Locale-independent conversion of ASCII isxdigit.246*/247static inline av_const int av_isxdigit(int c)248{249c = av_tolower(c);250return av_isdigit(c) || (c >= 'a' && c <= 'f');251}252253/**254* Locale-independent case-insensitive compare.255* @note This means only ASCII-range characters are case-insensitive256*/257int av_strcasecmp(const char *a, const char *b);258259/**260* Locale-independent case-insensitive compare.261* @note This means only ASCII-range characters are case-insensitive262*/263int av_strncasecmp(const char *a, const char *b, size_t n);264265/**266* Locale-independent strings replace.267* @note This means only ASCII-range characters are replace268*/269char *av_strireplace(const char *str, const char *from, const char *to);270271/**272* Thread safe basename.273* @param path the string to parse, on DOS both \ and / are considered separators.274* @return pointer to the basename substring.275* If path does not contain a slash, the function returns a copy of path.276* If path is a NULL pointer or points to an empty string, a pointer277* to a string "." is returned.278*/279const char *av_basename(const char *path);280281/**282* Thread safe dirname.283* @param path the string to parse, on DOS both \ and / are considered separators.284* @return A pointer to a string that's the parent directory of path.285* If path is a NULL pointer or points to an empty string, a pointer286* to a string "." is returned.287* @note the function may modify the contents of the path, so copies should be passed.288*/289const char *av_dirname(char *path);290291/**292* Match instances of a name in a comma-separated list of names.293* List entries are checked from the start to the end of the names list,294* the first match ends further processing. If an entry prefixed with '-'295* matches, then 0 is returned. The "ALL" list entry is considered to296* match all names.297*298* @param name Name to look for.299* @param names List of names.300* @return 1 on match, 0 otherwise.301*/302int av_match_name(const char *name, const char *names);303304/**305* Append path component to the existing path.306* Path separator '/' is placed between when needed.307* Resulting string have to be freed with av_free().308* @param path base path309* @param component component to be appended310* @return new path or NULL on error.311*/312char *av_append_path_component(const char *path, const char *component);313314enum AVEscapeMode {315AV_ESCAPE_MODE_AUTO, ///< Use auto-selected escaping mode.316AV_ESCAPE_MODE_BACKSLASH, ///< Use backslash escaping.317AV_ESCAPE_MODE_QUOTE, ///< Use single-quote escaping.318AV_ESCAPE_MODE_XML, ///< Use XML non-markup character data escaping.319};320321/**322* Consider spaces special and escape them even in the middle of the323* string.324*325* This is equivalent to adding the whitespace characters to the special326* characters lists, except it is guaranteed to use the exact same list327* of whitespace characters as the rest of libavutil.328*/329#define AV_ESCAPE_FLAG_WHITESPACE (1 << 0)330331/**332* Escape only specified special characters.333* Without this flag, escape also any characters that may be considered334* special by av_get_token(), such as the single quote.335*/336#define AV_ESCAPE_FLAG_STRICT (1 << 1)337338/**339* Within AV_ESCAPE_MODE_XML, additionally escape single quotes for single340* quoted attributes.341*/342#define AV_ESCAPE_FLAG_XML_SINGLE_QUOTES (1 << 2)343344/**345* Within AV_ESCAPE_MODE_XML, additionally escape double quotes for double346* quoted attributes.347*/348#define AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES (1 << 3)349350351/**352* Escape string in src, and put the escaped string in an allocated353* string in *dst, which must be freed with av_free().354*355* @param dst pointer where an allocated string is put356* @param src string to escape, must be non-NULL357* @param special_chars string containing the special characters which358* need to be escaped, can be NULL359* @param mode escape mode to employ, see AV_ESCAPE_MODE_* macros.360* Any unknown value for mode will be considered equivalent to361* AV_ESCAPE_MODE_BACKSLASH, but this behaviour can change without362* notice.363* @param flags flags which control how to escape, see AV_ESCAPE_FLAG_ macros364* @return the length of the allocated string, or a negative error code in case of error365* @see av_bprint_escape()366*/367av_warn_unused_result368int av_escape(char **dst, const char *src, const char *special_chars,369enum AVEscapeMode mode, int flags);370371#define AV_UTF8_FLAG_ACCEPT_INVALID_BIG_CODES 1 ///< accept codepoints over 0x10FFFF372#define AV_UTF8_FLAG_ACCEPT_NON_CHARACTERS 2 ///< accept non-characters - 0xFFFE and 0xFFFF373#define AV_UTF8_FLAG_ACCEPT_SURROGATES 4 ///< accept UTF-16 surrogates codes374#define AV_UTF8_FLAG_EXCLUDE_XML_INVALID_CONTROL_CODES 8 ///< exclude control codes not accepted by XML375376#define AV_UTF8_FLAG_ACCEPT_ALL \377AV_UTF8_FLAG_ACCEPT_INVALID_BIG_CODES|AV_UTF8_FLAG_ACCEPT_NON_CHARACTERS|AV_UTF8_FLAG_ACCEPT_SURROGATES378379/**380* Read and decode a single UTF-8 code point (character) from the381* buffer in *buf, and update *buf to point to the next byte to382* decode.383*384* In case of an invalid byte sequence, the pointer will be updated to385* the next byte after the invalid sequence and the function will386* return an error code.387*388* Depending on the specified flags, the function will also fail in389* case the decoded code point does not belong to a valid range.390*391* @note For speed-relevant code a carefully implemented use of392* GET_UTF8() may be preferred.393*394* @param codep pointer used to return the parsed code in case of success.395* The value in *codep is set even in case the range check fails.396* @param bufp pointer to the address the first byte of the sequence397* to decode, updated by the function to point to the398* byte next after the decoded sequence399* @param buf_end pointer to the end of the buffer, points to the next400* byte past the last in the buffer. This is used to401* avoid buffer overreads (in case of an unfinished402* UTF-8 sequence towards the end of the buffer).403* @param flags a collection of AV_UTF8_FLAG_* flags404* @return >= 0 in case a sequence was successfully read, a negative405* value in case of invalid sequence406*/407av_warn_unused_result408int av_utf8_decode(int32_t *codep, const uint8_t **bufp, const uint8_t *buf_end,409unsigned int flags);410411/**412* Check if a name is in a list.413* @returns 0 if not found, or the 1 based index where it has been found in the414* list.415*/416int av_match_list(const char *name, const char *list, char separator);417418/**419* See libc sscanf manual for more information.420* Locale-independent sscanf implementation.421*/422int av_sscanf(const char *string, const char *format, ...);423424/**425* @}426*/427428#endif /* AVUTIL_AVSTRING_H */429430431