<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16641">View Change</a></p><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">strings/json: Add string delimter match, and object create with vars methods<br><br>Add a function to check if there is an exact match a one string between<br>delimiters in another string.<br><br>Add a function that will create an ast_json object out of a list of<br>Asterisk variables. An excludes string can also optionally be passed<br>in.<br><br>Also, add a macro to make it easier to get object integers.<br><br>Change-Id: I5f34f18e102126aef3997f19a553a266d70d6226<br>---<br>M include/asterisk/json.h<br>M include/asterisk/strings.h<br>M main/json.c<br>M main/strings.c<br>M tests/test_json.c<br>M tests/test_strings.c<br>6 files changed, 250 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/json.h b/include/asterisk/json.h</span><br><span>index ce0baa4..3f485d1 100644</span><br><span>--- a/include/asterisk/json.h</span><br><span>+++ b/include/asterisk/json.h</span><br><span>@@ -539,6 +539,15 @@</span><br><span> struct ast_json *ast_json_object_create(void);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Create a new JSON object using the given variables</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param variables A list of Asterisk variables</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param excludes Comma separated string of variable names to exclude (optional)</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return Newly allocated object.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return \c NULL on error.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_json *ast_json_object_create_vars(const struct ast_variable *variables, const char *excludes);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Get size of JSON object.</span><br><span> * \since 12.0.0</span><br><span> * \param object JSON object.</span><br><span>@@ -573,6 +582,14 @@</span><br><span> #define ast_json_object_string_get(object, key) ast_json_string_get(ast_json_object_get(object, key))</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Get an integer field from a JSON object.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param integer JSON integer.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return Value of a JSON integer.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return 0 if \a integer is not a JSON integer.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+#define ast_json_object_integer_get(object, key) ast_json_integer_get(ast_json_object_get(object, key))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Set a field in a JSON object.</span><br><span> * \since 12.0.0</span><br><span> *</span><br><span>diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h</span><br><span>index 929cbf5..881cf89 100644</span><br><span>--- a/include/asterisk/strings.h</span><br><span>+++ b/include/asterisk/strings.h</span><br><span>@@ -401,6 +401,19 @@</span><br><span> )</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Check if there is an exact match for 'needle' between delimiters in 'haystack'.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \note This will skip extra leading spaces between delimiters.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param needle The string to search for</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param haystack The string searched in</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param delim The haystack delimiter</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return True if an exact match for needle is in haystack, false otherwise</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_in_delimited_string(const char *needle, const char *haystack, char delim);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> \brief Build a string in a buffer, designed to be called repeatedly</span><br><span> </span><br><span> \note This method is not recommended. New code should use ast_str_*() instead.</span><br><span>diff --git a/main/json.c b/main/json.c</span><br><span>index 09101aa..616b12e 100644</span><br><span>--- a/main/json.c</span><br><span>+++ b/main/json.c</span><br><span>@@ -852,3 +852,22 @@</span><br><span> </span><br><span> return ret;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_json *ast_json_object_create_vars(const struct ast_variable *variables, const char *excludes)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct ast_variable *i;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_json *obj;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ obj = ast_json_object_create();</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!obj) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = variables; i; i = i->next) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!excludes || !ast_in_delimited_string(i->name, excludes, ',')) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_json_object_set(obj, i->name, ast_json_string_create(i->value));</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return obj;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/main/strings.c b/main/strings.c</span><br><span>index 0cd4692..20769fa 100644</span><br><span>--- a/main/strings.c</span><br><span>+++ b/main/strings.c</span><br><span>@@ -430,3 +430,28 @@</span><br><span> </span><br><span> return 0;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_in_delimited_string(const char *needle, const char *haystack, char delim)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *end;</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned long needle_size;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_assert(haystack != NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!needle) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ needle_size = strlen(needle);</span><br><span style="color: hsl(120, 100%, 40%);">+ haystack = ast_skip_blanks(haystack);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ while ((end = strchr(haystack, delim))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (needle_size == end - haystack && !strncmp(haystack, needle, needle_size)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ haystack = ast_skip_blanks(end + 1);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return strcmp(haystack, needle) ? 0 : -1;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>diff --git a/tests/test_json.c b/tests/test_json.c</span><br><span>index 8dbb872..a14ac3a 100644</span><br><span>--- a/tests/test_json.c</span><br><span>+++ b/tests/test_json.c</span><br><span>@@ -37,6 +37,7 @@</span><br><span> </span><br><span> #include "asterisk.h"</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/config.h"</span><br><span> #include "asterisk/json.h"</span><br><span> #include "asterisk/module.h"</span><br><span> #include "asterisk/test.h"</span><br><span>@@ -1090,6 +1091,63 @@</span><br><span> return AST_TEST_PASS;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+AST_TEST_DEFINE(json_test_object_create_vars)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);</span><br><span style="color: hsl(120, 100%, 40%);">+ RAII_VAR(struct ast_variable *, vars, NULL, ast_variables_destroy);</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *value;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_variable *new_var;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (cmd) {</span><br><span style="color: hsl(120, 100%, 40%);">+ case TEST_INIT:</span><br><span style="color: hsl(120, 100%, 40%);">+ info->name = "object_create_vars";</span><br><span style="color: hsl(120, 100%, 40%);">+ info->category = CATEGORY;</span><br><span style="color: hsl(120, 100%, 40%);">+ info->summary = "Testing JSON object creation initialized using Asterisk variables.";</span><br><span style="color: hsl(120, 100%, 40%);">+ info->description = "Test JSON abstraction library.";</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_TEST_NOT_RUN;</span><br><span style="color: hsl(120, 100%, 40%);">+ case TEST_EXECUTE:</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* NULL case */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, (uut = ast_json_object_create_vars(NULL, NULL)));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !(value = ast_json_object_string_get(uut, "foo")));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, (new_var = ast_variable_new("foo", "bar", "")));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_variable_list_append(&vars, new_var);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, (new_var = ast_variable_new("bar", "baz", "")));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_variable_list_append(&vars, new_var);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Variables case */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_json_unref(uut);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, (uut = ast_json_object_create_vars(vars, NULL)));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, (value = ast_json_object_string_get(uut, "foo")));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !strcmp("bar", value));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, (value = ast_json_object_string_get(uut, "bar")));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !strcmp("baz", value));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Variables with excludes case */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_json_unref(uut);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, (uut = ast_json_object_create_vars(vars, "foo")));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !(value = ast_json_object_string_get(uut, "foo")));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, (value = ast_json_object_string_get(uut, "bar")));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !strcmp("baz", value));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_json_unref(uut);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, (uut = ast_json_object_create_vars(vars, "foo2")));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, (value = ast_json_object_string_get(uut, "foo")));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, (value = ast_json_object_string_get(uut, "bar")));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !strcmp("baz", value));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_json_unref(uut);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, (uut = ast_json_object_create_vars(vars, "foobar,baz")));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, (value = ast_json_object_string_get(uut, "foo")));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, (value = ast_json_object_string_get(uut, "bar")));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !strcmp("baz", value));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_TEST_PASS;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> AST_TEST_DEFINE(json_test_dump_load_string)</span><br><span> {</span><br><span> RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);</span><br><span>@@ -1738,6 +1796,7 @@</span><br><span> AST_TEST_UNREGISTER(json_test_object_null);</span><br><span> AST_TEST_UNREGISTER(json_test_object_iter);</span><br><span> AST_TEST_UNREGISTER(json_test_object_iter_null);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_TEST_UNREGISTER(json_test_object_create_vars);</span><br><span> AST_TEST_UNREGISTER(json_test_dump_load_string);</span><br><span> AST_TEST_UNREGISTER(json_test_dump_load_str);</span><br><span> AST_TEST_UNREGISTER(json_test_dump_str_fail);</span><br><span>@@ -1794,6 +1853,7 @@</span><br><span> AST_TEST_REGISTER(json_test_object_null);</span><br><span> AST_TEST_REGISTER(json_test_object_iter);</span><br><span> AST_TEST_REGISTER(json_test_object_iter_null);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_TEST_REGISTER(json_test_object_create_vars);</span><br><span> AST_TEST_REGISTER(json_test_dump_load_string);</span><br><span> AST_TEST_REGISTER(json_test_dump_load_str);</span><br><span> AST_TEST_REGISTER(json_test_dump_str_fail);</span><br><span>diff --git a/tests/test_strings.c b/tests/test_strings.c</span><br><span>index 3d697e5..63ac856 100644</span><br><span>--- a/tests/test_strings.c</span><br><span>+++ b/tests/test_strings.c</span><br><span>@@ -620,6 +620,120 @@</span><br><span> return AST_TEST_PASS;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+AST_TEST_DEFINE(in_delimited_string)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (cmd) {</span><br><span style="color: hsl(120, 100%, 40%);">+ case TEST_INIT:</span><br><span style="color: hsl(120, 100%, 40%);">+ info->name = "in_delimited_string";</span><br><span style="color: hsl(120, 100%, 40%);">+ info->category = "/main/strings/";</span><br><span style="color: hsl(120, 100%, 40%);">+ info->summary = "Test ast_in_delimited_string";</span><br><span style="color: hsl(120, 100%, 40%);">+ info->description = info->summary;</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_TEST_NOT_RUN;</span><br><span style="color: hsl(120, 100%, 40%);">+ case TEST_EXECUTE:</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Single letter */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("a", "a,b", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("b", "a,b", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("c", "a,b", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("aa", "a,b", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("bb", "a,b", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("a,", "a,b", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string(",b", "a,b", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("a,b", "a,b", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Bad delimiter (ends up being just a strcmp) */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("a", "a,b", '#'));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("b", "a,b", '#'));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("c", "a,b", '#'));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("aa", "a,b", '#'));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("bb", "a,b", '#'));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("a,", "a,b", '#'));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string(",b", "a,b", '#'));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("a,b", "a,b", '#'));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Multi letter */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("abc", "abc,def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("def", "abc,def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("a", "abc,def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("b", "abc,def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("c", "abc,def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("d", "abc,def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("e", "abc,def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("f", "abc,def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("abc,", "abc,def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string(",def", "abc,def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("abc,def", "abc,def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Embedded */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("abc", "abcdef,abc", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("abcdef", "abcdef,abc", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("abc", "abcdef,def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("def", "abcdef,abc", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("def", "abcdefghi,abc", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* NULL and empty values */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string(NULL, "abc,def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("abc", ",abc,def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("abc", "abc,def,", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("abc", "abc,,def,", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("def", "abc,,def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("def", ",abc,,def,", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("", ",abc,def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("", "abc,def,", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("", "abc,,def,", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("", "abc,def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Multi word */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("abc", "abc,def,ghi", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("def", "abc,def,ghi", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("ghi", "abc,def,ghi", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("a", "abc,def,ghi", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("d", "abc,def,ghi", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("g", "abc,def,ghi", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("ab", "abc,def,ghi", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("de", "abc,def,ghi", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, !ast_in_delimited_string("gh", "abc,def,ghi", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* With leading spaces */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("abc", " abc", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("abc", " abc, def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("def", " abc, def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("abc", " abc, def, ghi", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("def", " abc, def, ghi", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("ghi", " abc, def, ghi", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("abc", " abc", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("abc", " abc, def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("def", " abc, def", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("abc", " abc, def, ghi", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("def", " abc, def, ghi", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("ghi", " abc, def, ghi", ','));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* With leading spaces and space as a delimiter */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("abc", " abc", ' '));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("abc", " abc def", ' '));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("def", " abc def", ' '));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("abc", " abc def ghi", ' '));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("def", " abc def ghi", ' '));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, ast_in_delimited_string("ghi", " abc def ghi", ' '));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_TEST_PASS;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int unload_module(void)</span><br><span> {</span><br><span> AST_TEST_UNREGISTER(str_test);</span><br><span>@@ -630,6 +744,7 @@</span><br><span> AST_TEST_UNREGISTER(escape_test);</span><br><span> AST_TEST_UNREGISTER(strings_match);</span><br><span> AST_TEST_UNREGISTER(temp_strings);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_TEST_UNREGISTER(in_delimited_string);</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span>@@ -643,6 +758,7 @@</span><br><span> AST_TEST_REGISTER(escape_test);</span><br><span> AST_TEST_REGISTER(strings_match);</span><br><span> AST_TEST_REGISTER(temp_strings);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_TEST_REGISTER(in_delimited_string);</span><br><span> return AST_MODULE_LOAD_SUCCESS;</span><br><span> }</span><br><span> </span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/16641">change 16641</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/16641"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: I5f34f18e102126aef3997f19a553a266d70d6226 </div>
<div style="display:none"> Gerrit-Change-Number: 16641 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>