1793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/*
2793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Copyright (c) 2007 Mans Rullgard
3793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
4793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * This file is part of FFmpeg.
5793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
6793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * FFmpeg is free software; you can redistribute it and/or
7793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * modify it under the terms of the GNU Lesser General Public
8793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * License as published by the Free Software Foundation; either
9793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * version 2.1 of the License, or (at your option) any later version.
10793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
11793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * FFmpeg is distributed in the hope that it will be useful,
12793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * but WITHOUT ANY WARRANTY; without even the implied warranty of
13793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Lesser General Public License for more details.
15793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
16793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * You should have received a copy of the GNU Lesser General Public
17793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * License along with FFmpeg; if not, write to the Free Software
18793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
20793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
21793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef AVUTIL_AVSTRING_H
22793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define AVUTIL_AVSTRING_H
23793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
24793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include <stddef.h>
25793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "attributes.h"
26793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
27793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
28793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @addtogroup lavu_string
29793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @{
30793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
31793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
32793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
33793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Return non-zero if pfx is a prefix of str. If it is, *ptr is set to
34793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * the address of the first character in str after the prefix.
35793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
36793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param str input string
37793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param pfx prefix to test
38793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param ptr updated if the prefix is matched inside str
39793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @return non-zero if the prefix matches, zero otherwise
40793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
41793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerint av_strstart(const char *str, const char *pfx, const char **ptr);
42793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
43793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
44793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Return non-zero if pfx is a prefix of str independent of case. If
45793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * it is, *ptr is set to the address of the first character in str
46793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * after the prefix.
47793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
48793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param str input string
49793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param pfx prefix to test
50793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param ptr updated if the prefix is matched inside str
51793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @return non-zero if the prefix matches, zero otherwise
52793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
53793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerint av_stristart(const char *str, const char *pfx, const char **ptr);
54793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
55793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
56793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Locate the first case-independent occurrence in the string haystack
57793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * of the string needle.  A zero-length string needle is considered to
58793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * match at the start of haystack.
59793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
60793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * This function is a case-insensitive version of the standard strstr().
61793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
62793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param haystack string to search in
63793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param needle   string to search for
64793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @return         pointer to the located match within haystack
65793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *                 or a null pointer if no match
66793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
67793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerchar *av_stristr(const char *haystack, const char *needle);
68793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
69793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
70793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Locate the first occurrence of the string needle in the string haystack
71793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * where not more than hay_length characters are searched. A zero-length
72793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * string needle is considered to match at the start of haystack.
73793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
74793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * This function is a length-limited version of the standard strstr().
75793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
76793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param haystack   string to search in
77793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param needle     string to search for
78793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param hay_length length of string to search in
79793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @return           pointer to the located match within haystack
80793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *                   or a null pointer if no match
81793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
82793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerchar *av_strnstr(const char *haystack, const char *needle, size_t hay_length);
83793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
84793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
85793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Copy the string src to dst, but no more than size - 1 bytes, and
86793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * null-terminate dst.
87793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
88793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * This function is the same as BSD strlcpy().
89793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
90793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param dst destination buffer
91793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param src source string
92793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param size size of destination buffer
93793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @return the length of src
94793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
95793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @warning since the return value is the length of src, src absolutely
96793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * _must_ be a properly 0-terminated string, otherwise this will read beyond
97793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * the end of the buffer and possibly crash.
98793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
99793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersize_t av_strlcpy(char *dst, const char *src, size_t size);
100793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
101793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
102793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Append the string src to the string dst, but to a total length of
103793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * no more than size - 1 bytes, and null-terminate dst.
104793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
105793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * This function is similar to BSD strlcat(), but differs when
106793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * size <= strlen(dst).
107793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
108793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param dst destination buffer
109793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param src source string
110793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param size size of destination buffer
111793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @return the total length of src and dst
112793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
113793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @warning since the return value use the length of src and dst, these
114793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * absolutely _must_ be a properly 0-terminated strings, otherwise this
115793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * will read beyond the end of the buffer and possibly crash.
116793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
117793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersize_t av_strlcat(char *dst, const char *src, size_t size);
118793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
119793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
120793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Append output to a string, according to a format. Never write out of
121793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * the destination buffer, and always put a terminating 0 within
122793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * the buffer.
123793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param dst destination buffer (string to which the output is
124793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *  appended)
125793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param size total size of the destination buffer
126793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param fmt printf-compatible format string, specifying how the
127793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *  following parameters are used
128793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @return the length of the string that would have been generated
129793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *  if enough space had been available
130793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
131793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersize_t av_strlcatf(char *dst, size_t size, const char *fmt, ...) av_printf_format(3, 4);
132793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
133793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
134793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Print arguments following specified format into a large enough auto
135793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * allocated buffer. It is similar to GNU asprintf().
136793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param fmt printf-compatible format string, specifying how the
137793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *            following parameters are used.
138793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @return the allocated string
139793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @note You have to free the string yourself with av_free().
140793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
141793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerchar *av_asprintf(const char *fmt, ...) av_printf_format(1, 2);
142793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
143793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
144793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Convert a number to a av_malloced string.
145793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
146793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerchar *av_d2str(double d);
147793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
148793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
149793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Unescape the given string until a non escaped terminating char,
150793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * and return the token corresponding to the unescaped string.
151793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
152793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * The normal \ and ' escaping is supported. Leading and trailing
153793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * whitespaces are removed, unless they are escaped with '\' or are
154793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * enclosed between ''.
155793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
156793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param buf the buffer to parse, buf will be updated to point to the
157793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * terminating char
158793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param term a 0-terminated list of terminating chars
159793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @return the malloced unescaped string, which must be av_freed by
160793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * the user, NULL in case of allocation failure
161793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
162793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerchar *av_get_token(const char **buf, const char *term);
163793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
164793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
165793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Split the string into several tokens which can be accessed by
166793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * successive calls to av_strtok().
167793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
168793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * A token is defined as a sequence of characters not belonging to the
169793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * set specified in delim.
170793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
171793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * On the first call to av_strtok(), s should point to the string to
172793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * parse, and the value of saveptr is ignored. In subsequent calls, s
173793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * should be NULL, and saveptr should be unchanged since the previous
174793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * call.
175793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
176793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * This function is similar to strtok_r() defined in POSIX.1.
177793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
178793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param s the string to parse, may be NULL
179793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param delim 0-terminated list of token delimiters, must be non-NULL
180793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param saveptr user-provided pointer which points to stored
181793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * information necessary for av_strtok() to continue scanning the same
182793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * string. saveptr is updated to point to the next character after the
183793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * first delimiter found, or to NULL if the string was terminated
184793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @return the found token, or NULL when no token is found
185793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
186793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerchar *av_strtok(char *s, const char *delim, char **saveptr);
187793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
188793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
189793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Locale-independent conversion of ASCII isdigit.
190793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
191793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerint av_isdigit(int c);
192793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
193793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
194793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Locale-independent conversion of ASCII isgraph.
195793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
196793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerint av_isgraph(int c);
197793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
198793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
199793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Locale-independent conversion of ASCII isspace.
200793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
201793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerint av_isspace(int c);
202793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
203793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
204793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Locale-independent conversion of ASCII characters to uppercase.
205793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
206793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerstatic inline int av_toupper(int c)
207793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
208793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    if (c >= 'a' && c <= 'z')
209793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        c ^= 0x20;
210793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    return c;
211793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}
212793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
213793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
214793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Locale-independent conversion of ASCII characters to lowercase.
215793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
216793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerstatic inline int av_tolower(int c)
217793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
218793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    if (c >= 'A' && c <= 'Z')
219793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        c ^= 0x20;
220793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    return c;
221793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}
222793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
223793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
224793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Locale-independent conversion of ASCII isxdigit.
225793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
226793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerint av_isxdigit(int c);
227793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
228793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
229793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Locale-independent case-insensitive compare.
230793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @note This means only ASCII-range characters are case-insensitive
231793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
232793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerint av_strcasecmp(const char *a, const char *b);
233793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
234793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
235793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Locale-independent case-insensitive compare.
236793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @note This means only ASCII-range characters are case-insensitive
237793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
238793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerint av_strncasecmp(const char *a, const char *b, size_t n);
239793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
240793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
241793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
242793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Thread safe basename.
243793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param path the path, on DOS both \ and / are considered separators.
244793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @return pointer to the basename substring.
245793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
246793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerconst char *av_basename(const char *path);
247793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
248793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
249793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Thread safe dirname.
250793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param path the path, on DOS both \ and / are considered separators.
251793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @return the path with the separator replaced by the string terminator or ".".
252793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @note the function may change the input string.
253793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
254793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerconst char *av_dirname(char *path);
255793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
256793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerenum AVEscapeMode {
257793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    AV_ESCAPE_MODE_AUTO,      ///< Use auto-selected escaping mode.
258793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    AV_ESCAPE_MODE_BACKSLASH, ///< Use backslash escaping.
259793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    AV_ESCAPE_MODE_QUOTE,     ///< Use single-quote escaping.
260793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
261793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
262793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
263793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Consider spaces special and escape them even in the middle of the
264793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * string.
265793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
266793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * This is equivalent to adding the whitespace characters to the special
267793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * characters lists, except it is guaranteed to use the exact same list
268793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * of whitespace characters as the rest of libavutil.
269793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
270793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define AV_ESCAPE_FLAG_WHITESPACE 0x01
271793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
272793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
273793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Escape only specified special characters.
274793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Without this flag, escape also any characters that may be considered
275793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * special by av_get_token(), such as the single quote.
276793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
277793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define AV_ESCAPE_FLAG_STRICT 0x02
278793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
279793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
280793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Escape string in src, and put the escaped string in an allocated
281793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * string in *dst, which must be freed with av_free().
282793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
283793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param dst           pointer where an allocated string is put
284793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param src           string to escape, must be non-NULL
285793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param special_chars string containing the special characters which
286793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *                      need to be escaped, can be NULL
287793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param mode          escape mode to employ, see AV_ESCAPE_MODE_* macros.
288793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *                      Any unknown value for mode will be considered equivalent to
289793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *                      AV_ESCAPE_MODE_BACKSLASH, but this behaviour can change without
290793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *                      notice.
291793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @param flags         flags which control how to escape, see AV_ESCAPE_FLAG_ macros
292793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @return the length of the allocated string, or a negative error code in case of error
293793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @see av_bprint_escape()
294793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
295793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerint av_escape(char **dst, const char *src, const char *special_chars,
296793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler              enum AVEscapeMode mode, int flags);
297793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
298793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
299793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @}
300793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
301793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
302793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif /* AVUTIL_AVSTRING_H */
303