2 * Copyright (c) 2007 Mans Rullgard
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef AVUTIL_AVSTRING_H
22 #define AVUTIL_AVSTRING_H
27 * Return non-zero if pfx is a prefix of str. If it is, *ptr is set to
28 * the address of the first character in str after the prefix.
30 * @param str input string
31 * @param pfx prefix to test
32 * @param ptr updated if the prefix is matched inside str
33 * @return non-zero if the prefix matches, zero otherwise
35 int av_strstart(const char *str, const char *pfx, const char **ptr);
38 * Return non-zero if pfx is a prefix of str independent of case. If
39 * it is, *ptr is set to the address of the first character in str
42 * @param str input string
43 * @param pfx prefix to test
44 * @param ptr updated if the prefix is matched inside str
45 * @return non-zero if the prefix matches, zero otherwise
47 int av_stristart(const char *str, const char *pfx, const char **ptr);
50 * Locate the first case-independent occurrence in the string haystack
51 * of the string needle. A zero-length string needle is considered to
52 * match at the start of haystack.
54 * This function is a case-insensitive version of the standard strstr().
56 * @param haystack string to search in
57 * @param needle string to search for
58 * @return pointer to the located match within haystack
59 * or a null pointer if no match
61 char *av_stristr(const char *haystack, const char *needle);
64 * Copy the string src to dst, but no more than size - 1 bytes, and
67 * This function is the same as BSD strlcpy().
69 * @param dst destination buffer
70 * @param src source string
71 * @param size size of destination buffer
72 * @return the length of src
74 * WARNING: since the return value is the length of src, src absolutely
75 * _must_ be a properly 0-terminated string, otherwise this will read beyond
76 * the end of the buffer and possibly crash.
78 size_t av_strlcpy(char *dst, const char *src, size_t size);
81 * Append the string src to the string dst, but to a total length of
82 * no more than size - 1 bytes, and null-terminate dst.
84 * This function is similar to BSD strlcat(), but differs when
85 * size <= strlen(dst).
87 * @param dst destination buffer
88 * @param src source string
89 * @param size size of destination buffer
90 * @return the total length of src and dst
92 * WARNING: since the return value use the length of src and dst, these absolutely
93 * _must_ be a properly 0-terminated strings, otherwise this will read beyond
94 * the end of the buffer and possibly crash.
96 size_t av_strlcat(char *dst, const char *src, size_t size);
99 * Append output to a string, according to a format. Never write out of
100 * the destination buffer, and always put a terminating 0 within
102 * @param dst destination buffer (string to which the output is
104 * @param size total size of the destination buffer
105 * @param fmt printf-compatible format string, specifying how the
106 * following parameters are used
107 * @return the length of the string that would have been generated
108 * if enough space had been available
110 size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...);
113 * Convert a number to a av_malloced string.
115 char *av_d2str(double d);
118 * Unescape the given string until a non escaped terminating char,
119 * and return the token corresponding to the unescaped string.
121 * The normal \ and ' escaping is supported. Leading and trailing
122 * whitespaces are removed, unless they are escaped with '\' or are
123 * enclosed between ''.
125 * @param buf the buffer to parse, buf will be updated to point to the
127 * @param term a 0-terminated list of terminating chars
128 * @return the malloced unescaped string, which must be av_freed by
129 * the user, NULL in case of allocation failure
131 char *av_get_token(const char **buf, const char *term);
133 #endif /* AVUTIL_AVSTRING_H */