[PATCH 2/3] util: Introduce virStringListSearch

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

 



The function performs a case insensitive search in a string list.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 src/libvirt_private.syms |  1 +
 src/util/virstring.c     | 28 ++++++++++++++++++++++++++++
 src/util/virstring.h     |  3 +++
 3 files changed, 32 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 3dece252df..9448bca596 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2868,6 +2868,7 @@ virStringListJoin;
 virStringListLength;
 virStringListMerge;
 virStringListRemove;
+virStringListSearch;
 virStringMatch;
 virStringParsePort;
 virStringReplace;
diff --git a/src/util/virstring.c b/src/util/virstring.c
index 15f367af7c..17c3282043 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -1499,3 +1499,31 @@ virStringParsePort(const char *str,
 
     return 0;
 }
+
+
+/**
+ * virStringListSearch:
+ * @strings: string list
+ * @needle: string to be searched for
+ *
+ * Searches for @needle in @strings ignoring case. See virStringListHasString
+ * for case sensitive search.
+ *
+ * Returns the matching string in @strings or NULL if not found.
+ */
+const char *
+virStringListSearch(const char **strings,
+                    const char *needle)
+{
+    size_t i;
+
+    if (!strings)
+        return NULL;
+
+    for (i = 0; strings[i]; i++) {
+        if (STRCASEEQ(strings[i], needle))
+            return strings[i];
+    }
+
+    return NULL;
+}
diff --git a/src/util/virstring.h b/src/util/virstring.h
index fa2ec1df4d..90afd244f6 100644
--- a/src/util/virstring.h
+++ b/src/util/virstring.h
@@ -309,4 +309,7 @@ int virStringParsePort(const char *str,
                        unsigned int *port)
     ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
 
+const char *virStringListSearch(const char **strings,
+                                const char *needle);
+
 #endif /* __VIR_STRING_H__ */
-- 
2.17.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]

  Powered by Linux