]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tools: replace wcwidth() with g_unichar_* APIs
authorDaniel P. Berrangé <berrange@redhat.com>
Fri, 17 Jan 2020 13:40:54 +0000 (13:40 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Wed, 29 Jan 2020 14:51:39 +0000 (14:51 +0000)
The combination of g_unichar_iszerowidth and
g_unichar_iswide is sufficient to replicate the logic
of wcwidth() for libvirt.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
tests/vshtabletest.c
tools/vsh-table.c

index f2e0554f0a9679a7f90c23ee70f85e209917e883..0feda90b52cd2c078ea552ceb172f6f3c37a3168 100644 (file)
@@ -19,6 +19,7 @@
 #include <config.h>
 
 #include <locale.h>
+#include <wchar.h>
 #include <wctype.h>
 
 #include "internal.h"
index a2365b2c326e3b3cebce7afdee8ce8ef390db36b..e21514e86f3d9832c1e6c21f306dbc2b9782ec93 100644 (file)
@@ -261,7 +261,7 @@ vshTableSafeEncode(const char *s, size_t *width)
             } else {
                 memcpy(buf, p, len);
                 buf += len;
-                *width += wcwidth(wc);
+                *width += g_unichar_iszerowidth(wc) ? 0 : (g_unichar_iswide(wc) ? 2 : 1);
             }
             p += len;
         }