mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-03 11:11:05 +00:00
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:
committed by
Friendly Automation
parent
2e55c0fded
commit
ae97aaedb0
@@ -538,6 +538,15 @@ int ast_json_array_extend(struct ast_json *array, struct ast_json *tail);
|
||||
*/
|
||||
struct ast_json *ast_json_object_create(void);
|
||||
|
||||
/*!
|
||||
* \brief Create a new JSON object using the given variables
|
||||
* \param variables A list of Asterisk variables
|
||||
* \param excludes Comma separated string of variable names to exclude (optional)
|
||||
* \return Newly allocated object.
|
||||
* \return \c NULL on error.
|
||||
*/
|
||||
struct ast_json *ast_json_object_create_vars(const struct ast_variable *variables, const char *excludes);
|
||||
|
||||
/*!
|
||||
* \brief Get size of JSON object.
|
||||
* \since 12.0.0
|
||||
@@ -572,6 +581,14 @@ struct ast_json *ast_json_object_get(struct ast_json *object, const char *key);
|
||||
*/
|
||||
#define ast_json_object_string_get(object, key) ast_json_string_get(ast_json_object_get(object, key))
|
||||
|
||||
/*!
|
||||
* \brief Get an integer field from a JSON object.
|
||||
* \param integer JSON integer.
|
||||
* \return Value of a JSON integer.
|
||||
* \return 0 if \a integer is not a JSON integer.
|
||||
*/
|
||||
#define ast_json_object_integer_get(object, key) ast_json_integer_get(ast_json_object_get(object, key))
|
||||
|
||||
/*!
|
||||
* \brief Set a field in a JSON object.
|
||||
* \since 12.0.0
|
||||
|
@@ -400,6 +400,19 @@ void ast_copy_string(char *dst, const char *src, size_t size),
|
||||
}
|
||||
)
|
||||
|
||||
/*!
|
||||
* \brief Check if there is an exact match for 'needle' between delimiters in 'haystack'.
|
||||
*
|
||||
* \note This will skip extra leading spaces between delimiters.
|
||||
*
|
||||
* \param needle The string to search for
|
||||
* \param haystack The string searched in
|
||||
* \param delim The haystack delimiter
|
||||
*
|
||||
* \return True if an exact match for needle is in haystack, false otherwise
|
||||
*/
|
||||
int ast_in_delimited_string(const char *needle, const char *haystack, char delim);
|
||||
|
||||
/*!
|
||||
\brief Build a string in a buffer, designed to be called repeatedly
|
||||
|
||||
|
Reference in New Issue
Block a user