From nobody Mon Feb 9 02:51:12 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579779904; cv=none; d=zohomail.com; s=zohoarc; b=ZHhzyiJaQ8q1PI2SGhEsue0guQGi2hIT6vORYvQzUZhQhXDa235omsT5kNyItH7Z/LU4D4/y1rWOCMREi9APStlqptoo+sYj8OFSRXQPG0nPU4sKe0hgTMFVurVYqiLCvl8FBkvqsfXsrRvYLLVu2bdUr4QnDUibjvaIW91KhF4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579779904; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tAA77GDkpuzb7euWrgkYFXQHOoEQ2gZFa28SYq/VJ6c=; b=GV2MSLiATfZkqPiQJKKYM+9cZrrVY3P9KEd2CNpKOtx1AuDWitb55d7Woj/tSzQ0MSoK1Wp+rMJzCFEryU4hLB3MklT4Jir7r4+kfR2nOIR38earHJvGxzvXcskf1oeQS+MwC9+HHht4yKZo9NRlC4p8YOqzN/apGcKQR7CFMAk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1579779904927719.7332087758072; Thu, 23 Jan 2020 03:45:04 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-367-BuG-sjUVOYy4ipWS0LqzUg-1; Thu, 23 Jan 2020 06:43:54 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id DD198800D41; Thu, 23 Jan 2020 11:43:48 +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 B485410016E8; Thu, 23 Jan 2020 11:43:48 +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 7365A18089D8; Thu, 23 Jan 2020 11:43:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00NBhcNa025333 for ; Thu, 23 Jan 2020 06:43:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id D9C9985754; Thu, 23 Jan 2020 11:43:38 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (unknown [10.33.8.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9ADF85750; Thu, 23 Jan 2020 11:43:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579779903; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=tAA77GDkpuzb7euWrgkYFXQHOoEQ2gZFa28SYq/VJ6c=; b=PX9VPNcsy1KrCl0OME7o1WBACQECY2KWont/cKlrUkDLQXHzrW0sOqk0cbz0PZrSeyPQKE wLGMEf/AxwVDScS+xhQ1n7HJ0eV1tuETCs31fN/BBEtwQ3QcCRWueHKYzyLq7h9U6rAGc7 tZeoGcJ6tQ8NM5WHdB1WA0Sl+35gwXA= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 07/32] tools: replace wcwidth() with g_unichar_* APIs Date: Thu, 23 Jan 2020 11:43:00 +0000 Message-Id: <20200123114325.3860881-8-berrange@redhat.com> In-Reply-To: <20200123114325.3860881-1-berrange@redhat.com> References: <20200123114325.3860881-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com 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: , 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-MC-Unique: BuG-sjUVOYy4ipWS0LqzUg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The combination of g_unichar_iszerowidth and g_unichar_iswide is sufficient to replicate the logic of wcwidth() for libvirt. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Pavel Hrdina --- tests/vshtabletest.c | 8 ++------ tools/vsh-table.c | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/vshtabletest.c b/tests/vshtabletest.c index f2e0554f0a..54498b8a5a 100644 --- a/tests/vshtabletest.c +++ b/tests/vshtabletest.c @@ -155,14 +155,12 @@ testUnicodeArabic(const void *opaque G_GNUC_UNUSED) " 1 =EF=BB=89=EF=BA=AA=EF=BB=B4=EF=BB=9F =EF=BA=8E=EF= =BB=A0=EF=BA=9C=EF=BB=98=EF=BB=B4=EF=BB=9F =EF=BB=95=EF=BA=8E=EF=BB=A3 =EF= =BB=8A=EF=BB=A7, =D9=A3=D9=A0 =EF=BB=8E=EF=BB=B4=EF=BB=A8=EF=BB=B3=EF=BA=8D= =EF=BB=AE=EF=BA=98=EF=BB=A7=EF=BA=8E=EF=BB=A4=EF=BA=97 =EF=BA=8E=EF=BB=A0= =EF=BA=9B=EF=BA=8E=EF=BB=A0=EF=BA=9B=D8=8C =EF=BA=84=EF=BA=B3=EF=BA=AD, =EF= =BA=A9=EF=BB=AE=EF=BB=9F =EF=BA=A9=EF=BB=AE=EF=BB=9F. =EF=BA=84=EF=BB=A3= =EF=BA=8E=EF=BB=A3 =EF=BA=8D =EF=BA=8E=EF=BB=A7 =EF=BB=B2=EF=BB=9C=EF=BB=A7= \n" " =EF=BA=BA=EF=BB=94=EF=BA=A3=EF=BA=93 =EF=BA=96=EF=BB= =9C=EF=BA=98=EF=BB=B4=EF=BB=9B=EF=BA=8D=D9=8B =EF=BB=8A=EF=BB=9F, =EF=BA=8E= =EF=BB=A0=EF=BA=A0=EF=BB=A7=EF=BB=AD=EF=BA=A9 =EF=BB=AD=EF=BA=8E=EF=BB=A0= =EF=BB=8C=EF=BA=97=EF=BA=8D=EF=BA=A9 =EF=BA=B5= =EF=BA=AD\n"; vshTablePtr table; - wchar_t wc; =20 /* If this char is not classed as printable, the actual * output won't match what this test expects. The code * is still operating correctly, but we have different * layout */ - mbrtowc(&wc, "=D8=8C", MB_CUR_MAX, NULL); - if (!iswprint(wc)) + if (!g_unichar_isprint(g_utf8_get_char(","))) return EXIT_AM_SKIP; =20 table =3D vshTableNew("=EF=BB=A1=EF=BA=8D =EF=BB=A2=EF=BB=A3=EF=BA=8D = =EF=BB=95=EF=BA=8E=EF=BA=8C=EF=BB=A3=EF=BA=93", "=EF=BA=93 =EF=BA=8E=EF=BB= =A0=EF=BA=BC=EF=BB=8B", "=EF=BA=8D=EF=BB=B8=EF=BA=9C=EF=BB=A7=EF=BA=8E=EF= =BB=A7", NULL); @@ -197,14 +195,12 @@ testUnicodeZeroWidthChar(const void *opaque G_GNUC_UN= USED) " 1\u200B fedora28 run\u200Bning\n" " 2 rhel7.5 running\n"; char *act =3D NULL; - wchar_t wc; =20 /* If this char is not classed as printable, the actual * output won't match what this test expects. The code * is still operating correctly, but we have different * layout */ - mbrtowc(&wc, "\u200B", MB_CUR_MAX, NULL); - if (!iswprint(wc)) + if (!g_unichar_isprint(g_utf8_get_char("\u200B"))) return EXIT_AM_SKIP; =20 table =3D vshTableNew("I\u200Bd", "Name", "\u200BStatus", NULL); diff --git a/tools/vsh-table.c b/tools/vsh-table.c index a2365b2c32..e21514e86f 100644 --- a/tools/vsh-table.c +++ b/tools/vsh-table.c @@ -261,7 +261,7 @@ vshTableSafeEncode(const char *s, size_t *width) } else { memcpy(buf, p, len); buf +=3D len; - *width +=3D wcwidth(wc); + *width +=3D g_unichar_iszerowidth(wc) ? 0 : (g_unichar_isw= ide(wc) ? 2 : 1); } p +=3D len; } --=20 2.24.1