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 George Joseph
parent 1031a1805b
commit 67d1f881eb
6 changed files with 250 additions and 0 deletions

View File

@@ -852,3 +852,22 @@ struct ast_json *ast_json_channel_vars(struct varshead *channelvars)
return ret;
}
struct ast_json *ast_json_object_create_vars(const struct ast_variable *variables, const char *excludes)
{
const struct ast_variable *i;
struct ast_json *obj;
obj = ast_json_object_create();
if (!obj) {
return NULL;
}
for (i = variables; i; i = i->next) {
if (!excludes || !ast_in_delimited_string(i->name, excludes, ',')) {
ast_json_object_set(obj, i->name, ast_json_string_create(i->value));
}
}
return obj;
}