From 9e5e5d8625714c58546fad00b9d95bce7f3a1afb Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Mon, 12 Nov 2018 13:14:02 +0100 Subject: [PATCH 1/3] expose wcwidth and related to perl --- src/perl/common/Core.xs | 21 +++++++++++++++++++++ src/perl/textui/TextUI.xs | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/perl/common/Core.xs b/src/perl/common/Core.xs index 5d2f7bca..7c72f646 100644 --- a/src/perl/common/Core.xs +++ b/src/perl/common/Core.xs @@ -2,6 +2,8 @@ #include "module.h" #include "irssi-version.h" #include "core.h" +#include "utf8.h" +#include "recode.h" #include "pidwait.h" #include "session.h" @@ -687,6 +689,25 @@ CODE: OUTPUT: RETVAL +int +string_width(str) + char *str +C_ARGS: + str, is_utf8() ? TREAT_STRING_AS_UTF8 : TREAT_STRING_AS_BYTES + +void +string_chars_for_width(str, width) + char *str + unsigned int width +PREINIT: + int retval; + unsigned int bytes; +PPCODE: + retval = string_chars_for_width(str, is_utf8() ? TREAT_STRING_AS_UTF8 : TREAT_STRING_AS_BYTES, width, &bytes); + mXPUSHi(retval); + mXPUSHu(bytes); + + #******************************* MODULE = Irssi::Core PACKAGE = Irssi::Server #******************************* diff --git a/src/perl/textui/TextUI.xs b/src/perl/textui/TextUI.xs index e2f162a0..71545d14 100644 --- a/src/perl/textui/TextUI.xs +++ b/src/perl/textui/TextUI.xs @@ -205,6 +205,27 @@ gui_input_set_pos(pos) CODE: gui_entry_set_pos(active_entry, pos); +int +wcwidth(c) + char *c +CODE: + if (term_type == TERM_TYPE_UTF8) { + unichar chr = g_utf8_get_char_validated((const char *) c, -1); + + if (chr & 0x80000000) { + RETVAL = 1; + } else { + RETVAL = i_wcwidth(chr); + } + } else if (term_type != TERM_TYPE_BIG5 || + c[1] == '\0' || !is_big5(c[0], c[1])) { + RETVAL = 1; + } else { + RETVAL = 2; + } +OUTPUT: + RETVAL + MODULE = Irssi::TextUI PACKAGE = Irssi::UI::Window void From deaa1da55e3250badbdb3a769989cf5525b301e2 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Mon, 12 Nov 2018 14:11:27 +0100 Subject: [PATCH 2/3] cast to unsigned char --- src/perl/textui/TextUI.xs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/perl/textui/TextUI.xs b/src/perl/textui/TextUI.xs index 71545d14..35ea5759 100644 --- a/src/perl/textui/TextUI.xs +++ b/src/perl/textui/TextUI.xs @@ -218,7 +218,8 @@ CODE: RETVAL = i_wcwidth(chr); } } else if (term_type != TERM_TYPE_BIG5 || - c[1] == '\0' || !is_big5(c[0], c[1])) { + c[1] == '\0' || + !is_big5((unsigned char) c[0], (unsigned char) c[1])) { RETVAL = 1; } else { RETVAL = 2; From 288f220f875d4e4f00e86dd809c04aa805b49991 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Tue, 13 Nov 2018 00:14:15 +0100 Subject: [PATCH 3/3] fix width of byte codepoints --- src/perl/textui/TextUI.xs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/perl/textui/TextUI.xs b/src/perl/textui/TextUI.xs index 35ea5759..9f4fd0b0 100644 --- a/src/perl/textui/TextUI.xs +++ b/src/perl/textui/TextUI.xs @@ -220,7 +220,7 @@ CODE: } else if (term_type != TERM_TYPE_BIG5 || c[1] == '\0' || !is_big5((unsigned char) c[0], (unsigned char) c[1])) { - RETVAL = 1; + RETVAL = i_wcwidth((unsigned char) *c); } else { RETVAL = 2; }