[libvirt PATCH 07/32] tools: replace wcwidth() with g_unichar_* APIs

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

 



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é <berrange@xxxxxxxxxx>
---
 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              ﻉﺪﻴﻟ ﺎﻠﺜﻘﻴﻟ ﻕﺎﻣ ﻊﻧ, ٣٠ ﻎﻴﻨﻳﺍ ﻮﺘﻧﺎﻤﺗ ﺎﻠﺛﺎﻠﺛ، ﺄﺳﺭ, ﺩﻮﻟ   ﺩﻮﻟ. ﺄﻣﺎﻣ ﺍ ﺎﻧ ﻲﻜﻧ\n"
         " ﺺﻔﺣﺓ           ﺖﻜﺘﻴﻛﺍً ﻊﻟ, ﺎﻠﺠﻧﻭﺩ ﻭﺎﻠﻌﺗﺍﺩ                              ﺵﺭ\n";
     vshTablePtr table;
-    wchar_t wc;
 
     /* 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, "،", MB_CUR_MAX, NULL);
-    if (!iswprint(wc))
+    if (!g_unichar_isprint(g_utf8_get_char(",")))
         return EXIT_AM_SKIP;
 
     table = vshTableNew("ﻡﺍ ﻢﻣﺍ ﻕﺎﺌﻣﺓ", "ﺓ ﺎﻠﺼﻋ", "ﺍﻸﺜﻧﺎﻧ", NULL);
@@ -197,14 +195,12 @@ testUnicodeZeroWidthChar(const void *opaque G_GNUC_UNUSED)
         " 1\u200B    fedora28   run\u200Bning\n"
         " 2    rhel7.5    running\n";
     char *act = NULL;
-    wchar_t wc;
 
     /* 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;
 
     table = 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 += len;
-                *width += wcwidth(wc);
+                *width += g_unichar_iszerowidth(wc) ? 0 : (g_unichar_iswide(wc) ? 2 : 1);
             }
             p += len;
         }
-- 
2.24.1





[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