From nobody Sun Apr 28 20:37:52 2024 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1503058204317961.7892808210962; Fri, 18 Aug 2017 05:10:04 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 83DB9B16C; Fri, 18 Aug 2017 12:10:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A0986707AE; Fri, 18 Aug 2017 12:10:00 +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 011281800C8A; Fri, 18 Aug 2017 12:09:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7IC9vbT008843 for ; Fri, 18 Aug 2017 08:09:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id C1E2A63634; Fri, 18 Aug 2017 12:09:57 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CF5F6362D; Fri, 18 Aug 2017 12:09:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 83DB9B16C Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 18 Aug 2017 14:09:57 +0200 Message-Id: <5299355362f9fd531ad81d2c355b53c62a853fee.1503058116.git.pkrempa@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Pavel Hrdina , Peter Krempa Subject: [libvirt] [PATCH] util: string: Introduce virStringHasChars 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.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 18 Aug 2017 12:10:02 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The helper returns true if a string contains any of the given chars. virStringHasControlChars can be reimplemented using that helper. --- Pavel was loudly thinking about such function. It turns out that I have it ready on one of my branches. src/util/virstring.c | 23 +++++++++++++++++++---- src/util/virstring.h | 2 ++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/util/virstring.c b/src/util/virstring.c index 58abf9dd6..0288d1e67 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -1195,6 +1195,24 @@ virStringStripIPv6Brackets(char *str) } +/** + * virStringHasChars: + * @str: string to look for chars in + * @chars: chars to find in string @str + * + * Returns true if @str contains any of the chars in @chars. + */ +bool +virStringHasChars(const char *str, + const char *chars) +{ + if (!str) + return false; + + return str[strcspn(str, chars)] !=3D '\0'; +} + + static const char control_chars[] =3D "\x01\x02\x03\x04\x05\x06\x07" "\x08" /* \t \n */ "\x0B\x0C" /* \r */ "\x0E\x0F" @@ -1204,10 +1222,7 @@ static const char control_chars[] =3D bool virStringHasControlChars(const char *str) { - if (!str) - return false; - - return str[strcspn(str, control_chars)] !=3D '\0'; + return virStringHasChars(str, control_chars); } diff --git a/src/util/virstring.h b/src/util/virstring.h index ff5f0148d..1290fcce1 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -286,6 +286,8 @@ char *virStringReplace(const char *haystack, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); void virStringStripIPv6Brackets(char *str); +bool virStringHasChars(const char *str, + const char *chars); bool virStringHasControlChars(const char *str); void virStringStripControlChars(char *str); --=20 2.14.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list