strings/json: Add string delimter match, and object create with vars methods

Add a function to check if there is an exact match a one string between
delimiters in another string.

Add a function that will create an ast_json object out of a list of
Asterisk variables. An excludes string can also optionally be passed
in.

Also, add a macro to make it easier to get object integers.

Change-Id: I5f34f18e102126aef3997f19a553a266d70d6226
This commit is contained in:
Kevin Harwell
2021-10-21 12:29:11 -05:00
committed by Friendly Automation
parent ba3f6c0b1e
commit ed384e652c
6 changed files with 250 additions and 0 deletions

View File

@@ -430,3 +430,28 @@ int ast_vector_string_split(struct ast_vector_string *dest,
return 0;
}
int ast_in_delimited_string(const char *needle, const char *haystack, char delim)
{
const char *end;
unsigned long needle_size;
ast_assert(haystack != NULL);
if (!needle) {
return 0;
}
needle_size = strlen(needle);
haystack = ast_skip_blanks(haystack);
while ((end = strchr(haystack, delim))) {
if (needle_size == end - haystack && !strncmp(haystack, needle, needle_size)) {
return 1;
}
haystack = ast_skip_blanks(end + 1);
}
return strcmp(haystack, needle) ? 0 : -1;
}