Asterisk - The Open Source Telephony Project
21.4.1
|
String manipulation API. More...
#include "asterisk.h"
#include <regex.h>
#include "asterisk/strings.h"
#include "asterisk/pbx.h"
#include "asterisk/vector.h"
Go to the source code of this file.
Functions | |
int | __ast_str_helper (struct ast_str **buf, ssize_t max_len, int append, const char *fmt, va_list ap, const char *file, int lineno, const char *function) |
Core functionality of ast_str_(set|append)_va. More... | |
char * | __ast_str_helper2 (struct ast_str **buf, ssize_t maxlen, const char *src, size_t maxsrc, int append, int escapecommas) |
char * | ast_generate_random_string (char *buf, size_t size) |
Create a pseudo-random string of a fixed length. More... | |
int | ast_in_delimited_string (const char *needle, const char *haystack, char delim) |
Check if there is an exact match for 'needle' between delimiters in 'haystack'. More... | |
char * | ast_read_line_from_buffer (char **buffer) |
Read lines from a string buffer. More... | |
int | ast_str_container_add (struct ao2_container *str_container, const char *add) |
Adds a string to a string container allocated by ast_str_container_alloc. More... | |
struct ao2_container * | ast_str_container_alloc_options (enum ao2_alloc_opts opts, int buckets) |
Allocates a hash container for bare strings. More... | |
void | ast_str_container_remove (struct ao2_container *str_container, const char *remove) |
Removes a string from a string container allocated by ast_str_container_alloc. More... | |
int | ast_strings_equal (const char *str1, const char *str2) |
Compare strings for equality checking for NULL. More... | |
int | ast_strings_match (const char *left, const char *op, const char *right) |
Compares 2 strings using realtime-style operators. More... | |
int | ast_vector_string_split (struct ast_vector_string *dest, const char *input, const char *delim, int flags, int(*excludes_cmp)(const char *s1, const char *s2)) |
Append a string vector by splitting a string. More... | |
static int | str_cmp (void *lhs, void *rhs, int flags) |
static int | str_hash (const void *obj, const int flags) |
static int | str_sort (const void *lhs, const void *rhs, int flags) |
String manipulation API.
Definition in file strings.c.
int __ast_str_helper | ( | struct ast_str ** | buf, |
ssize_t | max_len, | ||
int | append, | ||
const char * | fmt, | ||
va_list | ap, | ||
const char * | file, | ||
int | lineno, | ||
const char * | function | ||
) |
Core functionality of ast_str_(set|append)_va.
core handler for dynamic strings. This is not meant to be called directly, but rather through the various wrapper macros ast_str_set(...) ast_str_append(...) ast_str_set_va(...) ast_str_append_va(...)
Definition at line 55 of file strings.c.
References _ast_str_make_space(), AST_DYNSTR_BUILD_FAILED, and ast_log_safe().
char* ast_generate_random_string | ( | char * | buf, |
size_t | size | ||
) |
Create a pseudo-random string of a fixed length.
This function is useful for generating a string whose randomness does not need to be across all time and space, does not need to be cryptographically secure, and needs to fit in a limited space.
This function will write a null byte at the final position in the buffer (buf[size - 1]). So if you pass in a size of 10, then this will generate a random 9-character string.
buf | Buffer to write random string into. |
size | The size of the buffer. |
Definition at line 226 of file strings.c.
int ast_in_delimited_string | ( | const char * | needle, |
const char * | haystack, | ||
char | delim | ||
) |
Check if there is an exact match for 'needle' between delimiters in 'haystack'.
needle | The string to search for |
haystack | The string searched in |
delim | The haystack delimiter |
true | If an exact match for needle is in haystack. |
false | otherwise |
Definition at line 433 of file strings.c.
References ast_skip_blanks().
Referenced by ast_json_object_create_vars().
char* ast_read_line_from_buffer | ( | char ** | buffer | ) |
Read lines from a string buffer.
[in,out] | buffer | A pointer to a char * string with either Unix or Windows line endings |
Both '\n' and '\r\n' are treated as single delimiters but consecutive occurrences of the delimiters are NOT considered to be a single delimiter. This preserves blank lines in the input.
macOS line endings ('\r') are not supported at this time.
Definition at line 371 of file strings.c.
int ast_str_container_add | ( | struct ao2_container * | str_container, |
const char * | add | ||
) |
Adds a string to a string container allocated by ast_str_container_alloc.
str_container | The container to which to add a string |
add | The string to add to the container |
zero | on success |
non-zero | if the operation failed |
Definition at line 205 of file strings.c.
References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_link, and ao2_ref.
Referenced by add_media_cb(), add_variant_cb(), ast_bridge_snapshot_create(), ast_dns_get_nameservers(), ast_endpoint_add_channel(), coreshowchannelmap_add_to_map(), event_session_alloc(), get_languages(), test_cel_peer_strings_match(), and topic_add_subscription().
struct ao2_container* ast_str_container_alloc_options | ( | enum ao2_alloc_opts | opts, |
int | buckets | ||
) |
Allocates a hash container for bare strings.
opts | Options to be provided to the container |
buckets | The number of buckets to use for the hash container |
NULL | if allocation failed |
Definition at line 200 of file strings.c.
References ao2_container_alloc_hash.
Referenced by action_coreshowchannelmap(), and ast_dns_get_nameservers().
void ast_str_container_remove | ( | struct ao2_container * | str_container, |
const char * | remove | ||
) |
Removes a string from a string container allocated by ast_str_container_alloc.
str_container | The container from which to remove a string |
remove | The string to remove from the container |
Definition at line 221 of file strings.c.
References OBJ_NODATA, OBJ_SEARCH_KEY, and OBJ_UNLINK.
Referenced by endpoint_cache_clear(), and test_cel_peer_strings_match().
int ast_strings_equal | ( | const char * | str1, |
const char * | str2 | ||
) |
Compare strings for equality checking for NULL.
This function considers NULL values as non-strings, thus a false condition. This means that it will return false if one, or both of the given values are NULL (i.e. two NULLs are not equal strings).
str1 | The string to compare to str2 |
str2 | The string to compare to str1 |
true | if valid strings and equal. |
false | otherwise. |
int ast_strings_match | ( | const char * | left, |
const char * | op, | ||
const char * | right | ||
) |
Compares 2 strings using realtime-style operators.
left | The left side of the equation |
op | The operator to apply |
right | The right side of the equation |
1 | matches |
0 | doesn't match |
Operators: "=", "!=", "<", "<=", ">", ">=": If both left and right can be converted to float, then they will be compared as such. Otherwise the result will be derived from strcmp(left, right). "regex": The right value will be compiled as a regular expression and matched against the left value. "like": Any '' character in the right value will be converted to '.*' and the resulting string will be handled as a regex. NULL , "": If the right value starts and ends with a '/' then it will be processed as a regex. Otherwise, same as "=".
Definition at line 247 of file strings.c.
References ast_str_append(), ast_str_buffer(), ast_str_set(), and ast_strdupa.
Referenced by ast_variables_match().
int ast_vector_string_split | ( | struct ast_vector_string * | dest, |
const char * | input, | ||
const char * | delim, | ||
int | flags, | ||
int(*)(const char *s1, const char *s2) | excludes_cmp | ||
) |
Append a string vector by splitting a string.
dest | Pointer to an initialized vector. |
input | String buffer to split. |
delim | String delimeter passed to strsep. |
flags | Processing options defined by ast_vector_string_split_flags. |
excludes_cmp | NULL or a function like strcmp to exclude duplicate strings. |
0 | Success |
-1 | Failure |
Definition at line 392 of file strings.c.
References ast_strdup, ast_strdupa, ast_strip(), AST_VECTOR_APPEND, AST_VECTOR_GET_CMP, AST_VECTOR_STRING_SPLIT_ALLOW_EMPTY, and AST_VECTOR_STRING_SPLIT_NO_TRIM.