summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/runewidth.ha16
-rw-r--r--tests/strwidth.ha2
-rw-r--r--tui/width.ha37
3 files changed, 55 insertions, 0 deletions
diff --git a/tests/runewidth.ha b/tests/runewidth.ha
index 5e570a5..820dcf0 100644
--- a/tests/runewidth.ha
+++ b/tests/runewidth.ha
@@ -6,4 +6,20 @@ fn runewidth() void = {
assert(tui::runewidth('ๅคง') == 2);
assert(tui::runewidth('ใ') == 2);
assert(tui::runewidth('๐Ÿ˜€') == 2);
+ assert(tui::runewidth('่ฟ‘') == 2);
+ assert(tui::runewidth('ใ') == 2);
+ assert(tui::runewidth('ใฎ') == 2);
+ assert(tui::runewidth('ใ•') == 2);
+ assert(tui::runewidth('ใ‚„') == 2);
+ assert(tui::runewidth('ใ') == 2);
+ assert(tui::runewidth('๐Ÿ˜ช') == 2);
+ assert(tui::runewidth('ใ€Œ') == 2);
+ assert(tui::runewidth('ใพ') == 2);
+ assert(tui::runewidth('่กŒ') == 2);
+ assert(tui::runewidth('ใ€') == 2);
+ assert(tui::runewidth('ใ‚ช') == 2);
+ assert(tui::runewidth('ใƒŽ') == 2);
+ assert(tui::runewidth('ใƒž') == 2);
+ assert(tui::runewidth('ใƒˆ') == 2);
+ assert(tui::runewidth('ใƒš') == 2);
};
diff --git a/tests/strwidth.ha b/tests/strwidth.ha
index e3863d6..2024ca9 100644
--- a/tests/strwidth.ha
+++ b/tests/strwidth.ha
@@ -3,4 +3,6 @@ use tui;
@test
fn strwidth() void = {
assert(tui::strwidth("ๅคงใ๐Ÿ˜€f") == 7);
+ assert(tui::strwidth("่ฟ‘ใ้ ใใฎใ•ใ•ใ‚„ใ๐Ÿ˜ชใ€Œใพ่กŒใ€ใ‚ชใƒŽใƒžใƒˆใƒš") == 38);
+ assert(tui::strwidth("ํž๋Ÿฌ๋ฝ€๋ชจ์จฉ็™’ใ—ใฎใƒ’ใƒผใƒฉใƒผใกใ‚ƒใ‚“") == 30);
};
diff --git a/tui/width.ha b/tui/width.ha
index f6d6078..cb4464a 100644
--- a/tui/width.ha
+++ b/tui/width.ha
@@ -1,5 +1,6 @@
use strings;
+//https://unicodeplus.com/
export fn runewidth(r: rune) uint = {
let ru = r: u32;
// emoticons: https://en.wikipedia.org/wiki/Emoticons_(Unicode_block)
@@ -18,6 +19,42 @@ export fn runewidth(r: rune) uint = {
if (ru >= '\U00004E00' && ru <= '\U00009FFF') {
return 2;
};
+ // CJK Symbols and Punctuation: https://en.wikipedia.org/wiki/CJK_Symbols_and_Punctuation
+ if (ru >= '\U00003000' && ru <= '\U0000303F') {
+ return 2;
+ };
+ // Hangul Syllables: https://en.wikipedia.org/wiki/Hangul_Syllables
+ if (ru >= '\U0000AC00' && ru <= '\U0000D7AF') {
+ return 2;
+ };
+ // Miscellaneous Symbols: https://en.wikipedia.org/wiki/Miscellaneous_Symbols_and_Pictographs
+ if (ru >= '\U00002600' && ru <= '\U000026FF') {
+ return 2;
+ };
+ // Miscellaneous Symbols and Pictographs: https://en.wikipedia.org/wiki/Miscellaneous_Symbols_and_Pictographs
+ if (ru >= '\U0001F300' && ru <= '\U0001F5FF') {
+ return 2;
+ };
+ // Dingbats: https://en.wikipedia.org/wiki/Dingbats_(Unicode_block)
+ if (ru >= '\U00002700' && ru <= '\U000027BF') {
+ return 2;
+ };
+ // Transport and Map symbols: https://en.wikipedia.org/wiki/Transport_and_Map_Symbols
+ if (ru >= '\U0001F680' && ru <= '\U0001F6FF') {
+ return 2;
+ };
+ // Supplemental Symbols and Pictographs: https://en.wikipedia.org/wiki/Supplemental_Symbols_and_Pictographs
+ if (ru >= '\U0001F900' && ru <= '\U0001F9FF') {
+ return 2;
+ };
+ // Miscellaneous Symbols and Arrows: https://en.wikipedia.org/wiki/Miscellaneous_Symbols_and_Arrows
+ if (ru >= '\U00002B00' && ru <= '\U00002BFF') {
+ return 2;
+ };
+ // Symbols and Pictographs Extended-A: https://en.wikipedia.org/wiki/Symbols_and_Pictographs_Extended-A
+ if (ru >= '\U0001FA70' && ru <= '\U0001FAFF') {
+ return 2;
+ };
return 1;
};