[PATCH 1/5] util: Add virStringGetFirstWithPrefix

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



That function takes string list and returns first string in that list
that starts with the @prefix parameter with that prefix being skipped as
the caller knows what it starts with (also for easier manipulation in
future).

Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---
 src/libvirt_private.syms |  1 +
 src/util/virstring.c     | 17 +++++++++++++++++
 src/util/virstring.h     |  2 ++
 3 files changed, 20 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index ff322d61083e..d22bde70e17d 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2170,6 +2170,7 @@ virStrdup;
 virStringArrayHasString;
 virStringFreeList;
 virStringFreeListCount;
+virStringGetFirstWithPrefix;
 virStringHasControlChars;
 virStringIsEmpty;
 virStringJoin;
diff --git a/src/util/virstring.c b/src/util/virstring.c
index 5794f968406e..31f77cd1a656 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -238,6 +238,23 @@ virStringArrayHasString(char **strings, const char *needle)
     return false;
 }

+char *
+virStringGetFirstWithPrefix(char **strings, const char *prefix)
+{
+    size_t i = 0;
+
+    if (!strings)
+        return NULL;
+
+    while (strings[i]) {
+        if (STRPREFIX(strings[i], prefix))
+            return strings[i] + strlen(prefix);
+        i++;
+    }
+
+    return NULL;
+}
+
 /* Like strtol, but produce an "int" result, and check more carefully.
    Return 0 upon success;  return -1 to indicate failure.
    When END_PTR is NULL, the byte after the final valid digit must be NUL.
diff --git a/src/util/virstring.h b/src/util/virstring.h
index e6dcb32e998c..f65a12652961 100644
--- a/src/util/virstring.h
+++ b/src/util/virstring.h
@@ -47,6 +47,8 @@ void virStringFreeListCount(char **strings, size_t count);
 size_t virStringListLen(const char **strings);

 bool virStringArrayHasString(char **strings, const char *needle);
+char *virStringGetFirstWithPrefix(char **strings, const char *prefix)
+    ATTRIBUTE_NONNULL(2);

 char *virArgvToString(const char *const *argv);

-- 
2.5.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]