FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Enumerations | Functions
String Manipulation
Common utility functions

Macros

#define AV_ESCAPE_FLAG_WHITESPACE   0x01
 Consider spaces special and escape them even in the middle of the string.
 
#define AV_ESCAPE_FLAG_STRICT   0x02
 Escape only specified special characters.
 
#define AV_UTF8_FLAG_ACCEPT_INVALID_BIG_CODES   1
 accept codepoints over 0x10FFFF
 
#define AV_UTF8_FLAG_ACCEPT_NON_CHARACTERS   2
 accept non-characters - 0xFFFE and 0xFFFF
 
#define AV_UTF8_FLAG_ACCEPT_SURROGATES   4
 accept UTF-16 surrogates codes
 
#define AV_UTF8_FLAG_EXCLUDE_XML_INVALID_CONTROL_CODES   8
 exclude control codes not accepted by XML
 
#define AV_UTF8_FLAG_ACCEPT_ALL   AV_UTF8_FLAG_ACCEPT_INVALID_BIG_CODES|AV_UTF8_FLAG_ACCEPT_NON_CHARACTERS|AV_UTF8_FLAG_ACCEPT_SURROGATES
 

Enumerations

enum  AVEscapeMode { AV_ESCAPE_MODE_AUTO, AV_ESCAPE_MODE_BACKSLASH, AV_ESCAPE_MODE_QUOTE }
 

Functions

int av_strstart (const char *str, const char *pfx, const char **ptr)
 Return non-zero if pfx is a prefix of str.
 
int av_stristart (const char *str, const char *pfx, const char **ptr)
 Return non-zero if pfx is a prefix of str independent of case.
 
char * av_stristr (const char *haystack, const char *needle)
 Locate the first case-independent occurrence in the string haystack of the string needle.
 
char * av_strnstr (const char *haystack, const char *needle, size_t hay_length)
 Locate the first occurrence of the string needle in the string haystack where not more than hay_length characters are searched.
 
size_t av_strlcpy (char *dst, const char *src, size_t size)
 Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
 
size_t av_strlcat (char *dst, const char *src, size_t size)
 Append the string src to the string dst, but to a total length of no more than size - 1 bytes, and null-terminate dst.
 
size_t av_strlcatf (char *dst, size_t size, const char *fmt,...) av_printf_format(3
 Append output to a string, according to a format.
 
size_t static size_t av_strnlen (const char *s, size_t len)
 Get the count of continuous non zero chars starting from the beginning.
 
char * av_asprintf (const char *fmt,...) av_printf_format(1
 Print arguments following specified format into a large enough auto allocated buffer.
 
char char * av_d2str (double d)
 Convert a number to a av_malloced string.
 
char * av_get_token (const char **buf, const char *term)
 Unescape the given string until a non escaped terminating char, and return the token corresponding to the unescaped string.
 
char * av_strtok (char *s, const char *delim, char **saveptr)
 Split the string into several tokens which can be accessed by successive calls to av_strtok().
 
int av_isdigit (int c)
 Locale-independent conversion of ASCII isdigit.
 
int av_isgraph (int c)
 Locale-independent conversion of ASCII isgraph.
 
int av_isspace (int c)
 Locale-independent conversion of ASCII isspace.
 
static int av_toupper (int c)
 Locale-independent conversion of ASCII characters to uppercase.
 
static int av_tolower (int c)
 Locale-independent conversion of ASCII characters to lowercase.
 
int av_isxdigit (int c)
 Locale-independent conversion of ASCII isxdigit.
 
int av_strcasecmp (const char *a, const char *b)
 Locale-independent case-insensitive compare.
 
int av_strncasecmp (const char *a, const char *b, size_t n)
 Locale-independent case-insensitive compare.
 
const char * av_basename (const char *path)
 Thread safe basename.
 
const char * av_dirname (char *path)
 Thread safe dirname.
 
int av_escape (char **dst, const char *src, const char *special_chars, enum AVEscapeMode mode, int flags)
 Escape string in src, and put the escaped string in an allocated string in *dst, which must be freed with av_free().
 
int av_utf8_decode (int32_t *codep, const uint8_t **bufp, const uint8_t *buf_end, unsigned int flags)
 Read and decode a single UTF-8 code point (character) from the buffer in *buf, and update *buf to point to the next byte to decode.
 

Detailed Description

Macro Definition Documentation

#define AV_ESCAPE_FLAG_WHITESPACE   0x01

Consider spaces special and escape them even in the middle of the string.

This is equivalent to adding the whitespace characters to the special characters lists, except it is guaranteed to use the exact same list of whitespace characters as the rest of libavutil.

Definition at line 285 of file avstring.h.

Referenced by av_bprint_escape(), main(), and segment_list_print_entry().

#define AV_ESCAPE_FLAG_STRICT   0x02

Escape only specified special characters.

Without this flag, escape also any characters that may be considered special by av_get_token(), such as the single quote.

Definition at line 292 of file avstring.h.

Referenced by av_bprint_escape(), and main().

#define AV_UTF8_FLAG_ACCEPT_INVALID_BIG_CODES   1

accept codepoints over 0x10FFFF

Definition at line 313 of file avstring.h.

Referenced by av_utf8_decode().

#define AV_UTF8_FLAG_ACCEPT_NON_CHARACTERS   2

accept non-characters - 0xFFFE and 0xFFFF

Definition at line 314 of file avstring.h.

Referenced by av_utf8_decode().

#define AV_UTF8_FLAG_ACCEPT_SURROGATES   4

accept UTF-16 surrogates codes

Definition at line 315 of file avstring.h.

Referenced by av_utf8_decode().

#define AV_UTF8_FLAG_EXCLUDE_XML_INVALID_CONTROL_CODES   8

exclude control codes not accepted by XML

Definition at line 316 of file avstring.h.

Referenced by av_utf8_decode(), and main().

Definition at line 318 of file avstring.h.

Enumeration Type Documentation

Enumerator:
AV_ESCAPE_MODE_AUTO 

Use auto-selected escaping mode.

AV_ESCAPE_MODE_BACKSLASH 

Use backslash escaping.

AV_ESCAPE_MODE_QUOTE 

Use single-quote escaping.

Definition at line 271 of file avstring.h.

Function Documentation

int av_strstart ( const char *  str,
const char *  pfx,
const char **  ptr 
)

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.

Parameters
strinput string
pfxprefix to test
ptrupdated if the prefix is matched inside str
Returns
non-zero if the prefix matches, zero otherwise

Definition at line 33 of file avstring.c.

Referenced by amr_parse_sdp_line(), asfrtp_parse_sdp_line(), bluray_open(), cache_open(), concat_open(), crypto_open2(), data_open(), ff_make_absolute_url(), ff_real_parse_sdp_a_line(), ff_wms_parse_sdp_a_line(), ffurl_alloc(), file_check(), hls_open(), http_open_cnx(), ilbc_parse_sdp_line(), latm_parse_sdp_line(), main(), md5_close(), open_output_file(), parse_command_line(), parse_h264_sdp_line(), parse_playlist(), parse_sdp_line(), rdt_parse_sdp_line(), rtsp_probe(), sap_probe(), subfile_open(), tls_open(), unix_open(), and xiph_parse_sdp_line().

int av_stristart ( 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.

Parameters
strinput string
pfxprefix to test
ptrupdated if the prefix is matched inside str
Returns
non-zero if the prefix matches, zero otherwise

Definition at line 44 of file avstring.c.

Referenced by av_stristr(), ff_http_auth_handle_header(), has_header(), and rtsp_parse_range_npt().

char* av_stristr ( const char *  haystack,
const char *  needle 
)

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().

Parameters
haystackstring to search in
needlestring to search for
Returns
pointer to the located match within haystack or a null pointer if no match

Definition at line 55 of file avstring.c.

Referenced by av_opencl_compile(), ftp_connect_control_connection(), ftp_features(), has_header(), http_start_receive_data(), mov_read_uuid(), run_implementation(), and sami_paragraph_to_ass().

char* av_strnstr ( const char *  haystack,
const char *  needle,
size_t  hay_length 
)

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().

Parameters
haystackstring to search in
needlestring to search for
hay_lengthlength of string to search in
Returns
pointer to the located match within haystack or a null pointer if no match

Definition at line 68 of file avstring.c.

size_t av_strlcpy ( char *  dst,
const char *  src,
size_t  size 
)

Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.

This function is the same as BSD strlcpy().

Parameters
dstdestination buffer
srcsource string
sizesize of destination buffer
Returns
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.

Definition at line 82 of file avstring.c.

Referenced by add_fragment(), amf_parse_object(), append_entry(), asf_read_language_list(), ass_encode_frame(), av_parse_color(), av_pix_fmt_swap_endianness(), av_strerror(), av_strlcat(), av_url_split(), avformat_alloc_output_context2(), avformat_open_input(), choose_qop(), compute_real_filename(), compute_status(), concat_open(), ctime1(), dprint_options(), dump_metadata(), ff_amf_get_field_value(), ff_img_read_header(), ff_make_absolute_url(), ff_rtsp_setup_output_streams(), find_compressor(), ftp_auth(), ftp_current_dir(), get_preset_file(), handle_connect_error(), hls_open(), http_connect(), http_parse_request(), id3v1_set_string(), id3v2_3_metadata_split_date(), main(), matroska_convert_tag(), merge_date(), mmsh_open_internal(), mov_text_encode_frame(), mov_text_new_line_cb(), mov_text_text_cb(), open_input(), open_output_file(), opt_channel_layout(), opt_default(), opt_preset(), opt_streamid(), parse_command(), parse_command_line(), parse_playlist(), parse_sws_flags(), pp_get_mode_by_name_and_quality(), rtmp_open(), rtp_new_connection(), rtp_open(), rtsp_parse_request(), sap_read_header(), sap_write_header(), set_encoder_id(), show_help_options(), srt_to_ass(), start_children(), stream_open(), udp_open(), unix_open(), url_find_protocol(), write_header(), and write_packet().

size_t av_strlcat ( char *  dst,
const char *  src,
size_t  size 
)

Append the string src to the string dst, but to a total length of no more than size - 1 bytes, and null-terminate dst.

This function is similar to BSD strlcat(), but differs when size <= strlen(dst).

Parameters
dstdestination buffer
srcsource string
sizesize of destination buffer
Returns
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.

Definition at line 92 of file avstring.c.

Referenced by av_dict_set(), av_printf_format(), avcodec_string(), ff_http_auth_create_response(), ff_make_absolute_url(), ff_rtsp_setup_input_streams(), ff_url_join(), ftp_open(), hls_write_header(), matroska_convert_tag(), mmsh_open_internal(), mov_open_dref(), mov_rewrite_dvd_sub_extradata(), opt_channel_layout(), rtmp_open(), rtp_new_connection(), rtsp_read_packet(), rtsp_send_reply(), set_encoder_id(), and show_help_options().

size_t av_strlcatf ( char *  dst,
size_t  size,
const char *  fmt,
  ... 
)

Append output to a string, according to a format.

Never write out of the destination buffer, and always put a terminating 0 within the buffer.

Parameters
dstdestination buffer (string to which the output is appended)
sizetotal size of the destination buffer
fmtprintf-compatible format string, specifying how the following parameters are used
Returns
the length of the string that would have been generated if enough space had been available
size_t static size_t av_strnlen ( const char *  s,
size_t  len 
)
inlinestatic

Get the count of continuous non zero chars starting from the beginning.

Parameters
lenmaximum number of characters to check in the string, that is the maximum value which is returned by the function

Definition at line 140 of file avstring.h.

Referenced by wc3_read_packet().

char* av_asprintf ( const char *  fmt,
  ... 
)

Print arguments following specified format into a large enough auto allocated buffer.

It is similar to GNU asprintf().

Parameters
fmtprintf-compatible format string, specifying how the following parameters are used.
Returns
the allocated string
Note
You have to free the string yourself with av_free().
char char* av_d2str ( double  d)

Convert a number to a av_malloced string.

Definition at line 138 of file avstring.c.

char* av_get_token ( const char **  buf,
const char *  term 
)

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 ''.

Parameters
bufthe buffer to parse, buf will be updated to point to the terminating char
terma 0-terminated list of terminating chars
Returns
the malloced unescaped string, which must be av_freed by the user, NULL in case of allocation failure

Definition at line 148 of file avstring.c.

Referenced by av_opt_get_key_value(), concat_read_header(), dilate_init(), expand_function(), opt_map(), opt_show_entries(), parse_command(), parse_filter(), parse_interval(), parse_key_value_pair(), parse_link_name(), set_params(), and tee_write_header().

char* av_strtok ( char *  s,
const char *  delim,
char **  saveptr 
)

Split the string into several tokens which can be accessed by successive calls to av_strtok().

A token is defined as a sequence of characters not belonging to the set specified in delim.

On the first call to av_strtok(), s should point to the string to parse, and the value of saveptr is ignored. In subsequent calls, s should be NULL, and saveptr should be unchanged since the previous call.

This function is similar to strtok_r() defined in POSIX.1.

Parameters
sthe string to parse, may be NULL
delim0-terminated list of token delimiters, must be non-NULL
saveptruser-provided pointer which points to stored information necessary for av_strtok() to continue scanning the same string. saveptr is updated to point to the next character after the first delimiter found, or to NULL if the string was terminated
Returns
the found token, or NULL when no token is found

Definition at line 183 of file avstring.c.

Referenced by config_input(), config_output(), fill_items(), frei0r_init(), ftp_auth(), ftp_passive_mode(), get_cookies(), init(), libssh_open(), main(), movie_common_init(), new_rendition(), opt_preset(), parse_bsfs(), parse_channel_expressions(), parse_frames(), parse_interval(), parse_times(), and sami_paragraph_to_ass().

int av_isdigit ( int  c)

Locale-independent conversion of ASCII isdigit.

Definition at line 288 of file avstring.c.

Referenced by av_get_frame_filename(), av_isxdigit(), av_parse_time(), channelmap_init(), date_get_num(), init(), and parse_value().

int av_isgraph ( int  c)

Locale-independent conversion of ASCII isgraph.

Definition at line 293 of file avstring.c.

Referenced by init_pattern_from_file(), init_pattern_from_string(), and read_shape_from_file().

int av_isspace ( int  c)
static int av_toupper ( int  c)
inlinestatic

Locale-independent conversion of ASCII characters to uppercase.

Definition at line 221 of file avstring.h.

Referenced by av_dict_get(), av_stristart(), avpriv_toupper4(), ff_hex_to_data(), ff_vorbis_comment(), get_jss_cmd(), jacosub_to_ass(), parse_ffconfig(), read_yesno(), and upcase_string().

static int av_tolower ( int  c)
inlinestatic

Locale-independent conversion of ASCII characters to lowercase.

Definition at line 231 of file avstring.h.

Referenced by av_isxdigit(), av_strcasecmp(), av_strncasecmp(), ff_urldecode(), microdvd_init(), parse_ffconfig(), and subviewer_read_header().

int av_isxdigit ( int  c)

Locale-independent conversion of ASCII isxdigit.

Definition at line 304 of file avstring.c.

Referenced by ff_urldecode(), and xbm_decode_frame().

int av_strcasecmp ( const char *  a,
const char *  b 
)
int av_strncasecmp ( const char *  a,
const char *  b,
size_t  n 
)
const char* av_basename ( const char *  path)

Thread safe basename.

Parameters
paththe path, on DOS both \ and / are considered separators.
Returns
pointer to the basename substring.

Definition at line 233 of file avstring.c.

Referenced by append_entry(), set_segment_filename(), and write_manifest().

const char* av_dirname ( char *  path)

Thread safe dirname.

Parameters
paththe path, on DOS both \ and / are considered separators.
Returns
the path with the separator replaced by the string terminator or ".".
Note
the function may change the input string.

Definition at line 250 of file avstring.c.

int av_escape ( char **  dst,
const char *  src,
const char *  special_chars,
enum AVEscapeMode  mode,
int  flags 
)

Escape string in src, and put the escaped string in an allocated string in *dst, which must be freed with av_free().

Parameters
dstpointer where an allocated string is put
srcstring to escape, must be non-NULL
special_charsstring containing the special characters which need to be escaped, can be NULL
modeescape mode to employ, see AV_ESCAPE_MODE_* macros. Any unknown value for mode will be considered equivalent to AV_ESCAPE_MODE_BACKSLASH, but this behaviour can change without notice.
flagsflags which control how to escape, see AV_ESCAPE_FLAG_ macros
Returns
the length of the allocated string, or a negative error code in case of error
See Also
av_bprint_escape()

Definition at line 271 of file avstring.c.

Referenced by avfilter_init_str(), main(), and segment_list_print_entry().

int av_utf8_decode ( int32_t codep,
const uint8_t **  bufp,
const uint8_t buf_end,
unsigned int  flags 
)

Read and decode a single UTF-8 code point (character) from the buffer in *buf, and update *buf to point to the next byte to decode.

In case of an invalid byte sequence, the pointer will be updated to the next byte after the invalid sequence and the function will return an error code.

Depending on the specified flags, the function will also fail in case the decoded code point does not belong to a valid range.

Note
For speed-relevant code a carefully implemented use of GET_UTF8() may be preferred.
Parameters
codeppointer used to return the parsed code in case of success. The value in codep is set even in case the range check fails.
bufp pointer to the address the first byte of the sequence to decode, updated by the function to point to the byte next after the decoded sequence
buf_endpointer to the end of the buffer, points to the next byte past the last in the buffer. This is used to avoid buffer overreads (in case of an unfinished UTF-8 sequence towards the end of the buffer).
flags a collection of AV_UTF8_FLAG_ flags
Returns
>= 0 in case a sequence was successfully read, a negative value in case of invalid sequence

Definition at line 310 of file avstring.c.

Referenced by validate_string(), and writer_open().