<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/7871">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Richard Mudgett: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Jenkins2: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">vector: Additional string vector definitions.<br><br>ast_vector_string_split:<br>This function will add items to an ast_vector_string by splitting values<br>of a string buffer.  Items are appended to the vector in the order they<br>are found.<br><br>ast_vector_const_string:<br>A vector of 'const char *'.<br><br>Change-Id: I1bf02a1efeb2baeea11c59c557d39dd1197494d7<br>---<br>M include/asterisk/vector.h<br>M main/strings.c<br>2 files changed, 73 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/include/asterisk/vector.h b/include/asterisk/vector.h<br>index 8bd1cef..d1b2973 100644<br>--- a/include/asterisk/vector.h<br>+++ b/include/asterisk/vector.h<br>@@ -51,8 +51,38 @@<br> /*! \brief Integer vector definition */<br> AST_VECTOR(ast_vector_int, int);<br> <br>-/*! \brief String vector definition */<br>+/*! \brief String vector definitions */<br> AST_VECTOR(ast_vector_string, char *);<br>+AST_VECTOR(ast_vector_const_string, const char *);<br>+<br>+/*! Options to override default processing of ast_vector_string_split. */<br>+enum ast_vector_string_split_flags {<br>+        /*! Do not trim whitespace from values. */<br>+   AST_VECTOR_STRING_SPLIT_NO_TRIM = 0x01,<br>+      /*! Append empty strings to the vector. */<br>+   AST_VECTOR_STRING_SPLIT_ALLOW_EMPTY = 0x02,<br>+};<br>+<br>+/*!<br>+ * \brief Append a string vector by splitting a string.<br>+ *<br>+ * \param dest Pointer to an initialized vector.<br>+ * \param input String buffer to split.<br>+ * \param delim String delimeter passed to strsep.<br>+ * \param flags Processing options defined by \ref enum ast_vector_string_split_flags.<br>+ * \param excludes_cmp NULL or a function like strcmp to exclude duplicate strings.<br>+ *<br>+ * \retval 0 Success<br>+ * \retval -1 Failure<br>+ *<br>+ * \note All elements added to the vector are allocated.  The caller is always<br>+ *       responsible for calling ast_free on each element in the vector even<br>+ *       after failure.  It's possible for this function to successfully add<br>+ *       some elements before failing.<br>+ */<br>+int ast_vector_string_split(struct ast_vector_string *dest,<br>+   const char *input, const char *delim, int flags,<br>+     int (*excludes_cmp)(const char *s1, const char *s2));<br> <br> /*!<br>  * \brief Define a vector structure with a read/write lock<br>diff --git a/main/strings.c b/main/strings.c<br>index 82e315a..ad96df2 100644<br>--- a/main/strings.c<br>+++ b/main/strings.c<br>@@ -40,6 +40,7 @@<br> #include <regex.h><br> #include "asterisk/strings.h"<br> #include "asterisk/pbx.h"<br>+#include "asterisk/vector.h"<br> <br> /*!<br>  * core handler for dynamic strings.<br>@@ -389,3 +390,44 @@<br> <br>  return start;<br> }<br>+<br>+int ast_vector_string_split(struct ast_vector_string *dest,<br>+   const char *input, const char *delim, int flags,<br>+     int (*excludes_cmp)(const char *s1, const char *s2))<br>+{<br>+     char *buf;<br>+   char *cur;<br>+   int no_trim = flags & AST_VECTOR_STRING_SPLIT_NO_TRIM;<br>+   int allow_empty = flags & AST_VECTOR_STRING_SPLIT_ALLOW_EMPTY;<br>+<br>+        ast_assert(dest != NULL);<br>+    ast_assert(!ast_strlen_zero(delim));<br>+<br>+      if (ast_strlen_zero(input)) {<br>+                return 0;<br>+    }<br>+<br>+ buf = ast_strdupa(input);<br>+    while ((cur = strsep(&buf, delim))) {<br>+            if (!no_trim) {<br>+                      cur = ast_strip(cur);<br>+                }<br>+<br>+         if (!allow_empty && ast_strlen_zero(cur)) {<br>+                  continue;<br>+            }<br>+<br>+         if (excludes_cmp && AST_VECTOR_GET_CMP(dest, cur, !excludes_cmp)) {<br>+                  continue;<br>+            }<br>+<br>+         cur = ast_strdup(cur);<br>+               if (!cur || AST_VECTOR_APPEND(dest, cur)) {<br>+                  ast_free(cur);<br>+<br>+                    return -1;<br>+           }<br>+    }<br>+<br>+ return 0;<br>+}<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7871">change 7871</a>. To unsubscribe, 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/7871"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I1bf02a1efeb2baeea11c59c557d39dd1197494d7 </div>
<div style="display:none"> Gerrit-Change-Number: 7871 </div>
<div style="display:none"> Gerrit-PatchSet: 9 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>