[epiphany] Add helpers for adding and removing items from a strv
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Add helpers for adding and removing items from a strv
- Date: Sun, 22 Jan 2017 23:55:52 +0000 (UTC)
commit b8811db568f939a6d7cb07e6e4dc7d72ec907069
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sun Jan 22 17:06:20 2017 -0600
Add helpers for adding and removing items from a strv
lib/ephy-string.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/ephy-string.h | 5 ++++
2 files changed, 64 insertions(+), 0 deletions(-)
---
diff --git a/lib/ephy-string.c b/lib/ephy-string.c
index 69ea3a3..de44d4e 100644
--- a/lib/ephy-string.c
+++ b/lib/ephy-string.c
@@ -242,3 +242,62 @@ ephy_string_commandline_args_to_uris (char **arguments, GError **error)
return args;
}
+
+char **
+ephy_strv_append (const char * const *strv,
+ const char *str)
+{
+ char **new_strv;
+ char **n;
+ const char * const *s;
+ guint len;
+
+ if (g_strv_contains (strv, str))
+ return g_strdupv ((char **)strv);
+
+ /* Needs room for one more string than before, plus one for trailing NULL. */
+ len = g_strv_length ((char **)strv);
+ new_strv = g_malloc ((len + 1 + 1) * sizeof (char *));
+ n = new_strv;
+ s = strv;
+
+ while (*s != NULL) {
+ *n = g_strdup (*s);
+ n++;
+ s++;
+ }
+ new_strv[len] = g_strdup (str);
+ new_strv[len + 1] = NULL;
+
+ return new_strv;
+}
+
+char **
+ephy_strv_remove (const char * const *strv,
+ const char *str)
+{
+ char **new_strv;
+ char **n;
+ const char * const *s;
+ guint len;
+
+ if (!g_strv_contains (strv, str))
+ return g_strdupv ((char **)strv);
+
+ /* Needs room for one fewer string than before, plus one for trailing NULL. */
+ len = g_strv_length ((char **)strv);
+ new_strv = g_malloc ((len - 1 + 1) * sizeof (char *));
+ n = new_strv;
+ s = strv;
+
+ while (*s != NULL) {
+ if (strcmp (*s, str) != 0) {
+ *n = g_strdup (*s);
+ n++;
+ }
+ s++;
+ }
+ new_strv[len - 1] = NULL;
+
+ return new_strv;
+}
diff --git a/lib/ephy-string.h b/lib/ephy-string.h
index 614a6e1..af9edc5 100644
--- a/lib/ephy-string.h
+++ b/lib/ephy-string.h
@@ -40,5 +40,10 @@ char *ephy_string_get_host_name (const char *url);
char **ephy_string_commandline_args_to_uris (char **arguments, GError **error);
+char **ephy_strv_append (const char * const *strv,
+ const char *str);
+char **ephy_strv_remove (const char * const *strv,
+ const char *str);
+
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]