diff --git a/lib/Terminal/WCWidth.rakumod b/lib/Terminal/WCWidth.rakumod index 79ebae9..5c64e50 100755 --- a/lib/Terminal/WCWidth.rakumod +++ b/lib/Terminal/WCWidth.rakumod @@ -37,10 +37,17 @@ my sub wcwidth(Int:D $ucs) is export { my sub wcswidth($str) is export { my $res = 0; + my $prev-w = 0; for $str.NFC { + if $_ == 0xFE0F && $prev-w == 1 { + $res += 1; + $prev-w = 0; + next; + } my $w = wcwidth($_); return -1 if $w < 0; $res += $w; + $prev-w = $w; } $res } diff --git a/t/01-basic.rakutest b/t/01-basic.rakutest index ae78741..21f8ba4 100755 --- a/t/01-basic.rakutest +++ b/t/01-basic.rakutest @@ -1,7 +1,7 @@ use Test; use Terminal::WCWidth; -plan 12; +plan 16; sub assert-length( $str, @each, $phrase, $msg = "wcwidth test" @@ -47,4 +47,17 @@ assert-length("\x1B13\x1B28\x1B2E\x1B44", "Balinese kapal (ship) is ᬓᬨᬮ᭄ of length 4." ); +# VS16 (U+FE0F) turns text characters into emoji presentation (width 2) +assert-length("\x2747\xFE0F", + (1, 0), + 2, + "❇️ (U+2747 + VS16): is of length 2" +); + +assert-length("\x2603\xFE0F", + (1, 0), + 2, + "☃️ (U+2603 + VS16): is of length 2" +); + # vim: expandtab shiftwidth=4