[Asterisk-code-review] vector: Additional string vector definitions. (asterisk[master])
Corey Farrell
asteriskteam at digium.com
Mon Jan 8 16:06:36 CST 2018
Corey Farrell has uploaded this change for review. ( https://gerrit.asterisk.org/7871
Change subject: vector: Additional string vector definitions.
......................................................................
vector: Additional string vector definitions.
ast_ast_vector_string_create:
This function will add items to an ast_vector_string by splitting values
of a string buffer. Items are appended to the vector in the order they
are found. Ignoring duplicates is supported.
ast_vector_const_string:
A vector of 'const char *'.
Change-Id: I1bf02a1efeb2baeea11c59c557d39dd1197494d7
---
M include/asterisk/vector.h
M main/strings.c
2 files changed, 48 insertions(+), 1 deletion(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/71/7871/1
diff --git a/include/asterisk/vector.h b/include/asterisk/vector.h
index 8bd1cef..f13b31c 100644
--- a/include/asterisk/vector.h
+++ b/include/asterisk/vector.h
@@ -51,8 +51,21 @@
/*! \brief Integer vector definition */
AST_VECTOR(ast_vector_int, int);
-/*! \brief String vector definition */
+/*! \brief String vector definitions */
AST_VECTOR(ast_vector_string, char *);
+AST_VECTOR(ast_vector_const_string, const char *);
+
+/*!
+ * \brief Create a string vector by splitting a string.
+ *
+ * \param dest Pointer to an initialized vector.
+ * \param input String buffer to split.
+ * \param delim String delimeter passed to strsep.
+ * \param ignore_dups Set non-zero to ignore all duplicate strings.
+ */
+int ast_vector_string_create(struct ast_vector_string *dest,
+ const char *input, const char *delim,
+ int (*ignore_cmp)(const char *s1, const char *s2));
/*!
* \brief Define a vector structure with a read/write lock
diff --git a/main/strings.c b/main/strings.c
index 82e315a..2bed9b2 100644
--- a/main/strings.c
+++ b/main/strings.c
@@ -40,6 +40,7 @@
#include <regex.h>
#include "asterisk/strings.h"
#include "asterisk/pbx.h"
+#include "asterisk/vector.h"
/*!
* core handler for dynamic strings.
@@ -389,3 +390,36 @@
return start;
}
+
+int ast_vector_string_create(struct ast_vector_string *dest,
+ const char *input, const char *delim,
+ int (*ignore_cmp)(const char *s1, const char *s2))
+{
+ char *buf;
+ char *cur;
+
+ if (ast_strlen_zero(input)) {
+ return 0;
+ }
+
+ buf = ast_strdupa(input);
+
+ ast_assert(dest != NULL);
+ ast_assert(buf != NULL);
+ ast_assert(!ast_strlen_zero(delim));
+
+ while ((cur = strsep(&buf, delim))) {
+ if (ignore_cmp && AST_VECTOR_GET_CMP(dest, cur, !ignore_cmp)) {
+ continue;
+ }
+
+ cur = ast_strdup(cur);
+ if (!cur || AST_VECTOR_APPEND(dest, cur)) {
+ ast_free(cur);
+
+ return -1;
+ }
+ }
+
+ return 0;
+}
--
To view, visit https://gerrit.asterisk.org/7871
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1bf02a1efeb2baeea11c59c557d39dd1197494d7
Gerrit-Change-Number: 7871
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180108/74acce72/attachment-0001.html>
More information about the asterisk-code-review
mailing list