From nobody Wed May 14 02:33:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1526571280867469.27536471308963; Thu, 17 May 2018 08:34:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EF0B730C6B36; Thu, 17 May 2018 15:34:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BE5ED1001F5C; Thu, 17 May 2018 15:34:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 68D044CAA8; Thu, 17 May 2018 15:34:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4HFXUmm029662 for ; Thu, 17 May 2018 11:33:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id BBA67ADF99; Thu, 17 May 2018 15:33:30 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 991D6ADF95 for ; Thu, 17 May 2018 15:33:28 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 6A7E6102EDD; Thu, 17 May 2018 17:33:27 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Thu, 17 May 2018 17:33:25 +0200 Message-Id: <2635e8a3debff8f1331cd4a675c1e14c5ad8db8d.1526570946.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/3] util: Introduce virStringListSearch X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 17 May 2018 15:34:39 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The function performs a case insensitive search in a string list. Signed-off-by: Jiri Denemark --- 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, =20 return 0; } + + +/** + * virStringListSearch: + * @strings: string list + * @needle: string to be searched for + * + * Searches for @needle in @strings ignoring case. See virStringListHasStr= ing + * 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 =3D 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; =20 +const char *virStringListSearch(const char **strings, + const char *needle); + #endif /* __VIR_STRING_H__ */ --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list