Changeset: f66320f463bb for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/f66320f463bb
Modified Files:
        clients/mapiclient/mclient.c
        cmake/monetdb-defines.cmake
        monetdb5/modules/atoms/str.c
        monetdb_config.h.in
Branch: default
Log Message:

Use Posix function wcwidth if available to determine display width of 
characters.


diffs (104 lines):

diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -47,6 +47,10 @@
 
 #include <locale.h>
 
+#ifdef HAVE_WCWIDTH
+#include <wchar.h>
+#endif
+
 #ifdef HAVE_ICONV
 #include <iconv.h>
 #ifdef HAVE_NL_LANGINFO
@@ -413,6 +417,14 @@ utf8strlenmax(char *s, char *e, size_t m
                        c = (c << 6) | (*s & 0x3F);
                        if (--n == 0) {
                                /* last byte of a multi-byte character */
+#ifdef HAVE_WCWIDTH
+                               n = wcwidth(c);
+                               if (n >= 0)
+                                       len += n;
+                               else
+                                       len++;          /* assume width 1 if 
unprintable */
+                               n = 0;
+#else
                                len++;
                                /* this list was created by combining
                                 * the code points marked as
@@ -546,7 +558,7 @@ utf8strlenmax(char *s, char *e, size_t m
                                        len++;
                                else if (0x0080 <= c && c <= 0x009F)
                                        len += 5;
-
+#endif
                        }
                } else if ((*s & 0xE0) == 0xC0) {
                        assert(n == 0);
diff --git a/cmake/monetdb-defines.cmake b/cmake/monetdb-defines.cmake
--- a/cmake/monetdb-defines.cmake
+++ b/cmake/monetdb-defines.cmake
@@ -118,6 +118,7 @@ function(monetdb_configure_defines)
   check_function_exists("task_info" HAVE_TASK_INFO)
   check_function_exists("times" HAVE_TIMES)
   check_function_exists("uname" HAVE_UNAME)
+  check_symbol_exists("wcwidth" "wchar.h" HAVE_WCWIDTH)
   # Some libc versions on Linux distributions don't have it
   check_symbol_exists("semtimedop" "sys/types.h;sys/ipc.h;sys/sem.h" 
HAVE_SEMTIMEDOP)
   cmake_push_check_state()
diff --git a/monetdb5/modules/atoms/str.c b/monetdb5/modules/atoms/str.c
--- a/monetdb5/modules/atoms/str.c
+++ b/monetdb5/modules/atoms/str.c
@@ -69,6 +69,9 @@
 #include <iconv.h>
 #include <locale.h>
 #endif
+#ifdef HAVE_WCWIDTH
+#include <wchar.h>
+#endif
 #include "mal_interpreter.h"
 
 #include "utf8.h"
@@ -3164,6 +3167,7 @@ str_strlen(const char *restrict s)
        return (int) pos;
 }
 
+/* return the display width of s */
 int
 UTF8_strwidth(const char *restrict s)
 {
@@ -3184,6 +3188,14 @@ UTF8_strwidth(const char *restrict s)
                        c = (c << 6) | (*s & 0x3F);
                        if (--n == 0) {
                                /* last byte of a multi-byte character */
+#ifdef HAVE_WCWIDTH
+                               n = wcwidth(c);
+                               if (n >= 0)
+                                       len += n;
+                               else
+                                       len++;          /* assume width 1 if 
unprintable */
+                               n = 0;
+#else
                                len++;
                                /* this list was created by combining
                                 * the code points marked as
@@ -3299,6 +3311,7 @@ UTF8_strwidth(const char *restrict s)
                                        (0x20000 <= c && c <= 0x2FFFD) ||
                                        (0x30000 <= c && c <= 0x3FFFD))
                                        len++;
+#endif
                        }
                } else if ((*s & 0xE0) == 0xC0) {
                        assert(n == 0);
diff --git a/monetdb_config.h.in b/monetdb_config.h.in
--- a/monetdb_config.h.in
+++ b/monetdb_config.h.in
@@ -172,6 +172,7 @@
 #cmakedefine HAVE_TIMES 1
 #cmakedefine HAVE_TM_GMTOFF 1
 #cmakedefine HAVE_UNAME 1
+#cmakedefine HAVE_WCWIDTH 1
 // #cmakedefine HAVE_SEMTIMEDOP
 #cmakedefine HAVE_PTHREAD_KILL 1
 #cmakedefine HAVE_PTHREAD_SETNAME_NP 1
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to