summaryrefslogtreecommitdiffstats
path: root/src/unicode-extra.c
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2016-06-04 18:32:24 -0400
committerJesse Luehrs <doy@tozt.net>2016-06-04 18:32:24 -0400
commitbd9fc2ba0396f04df399c1f685aacced84128518 (patch)
treef3b6edc4fa5608d1de13617211d4e8fa917376d2 /src/unicode-extra.c
parentebdda206434a93f5715aff55b0e9f59d03202d48 (diff)
downloadlibvt100-bd9fc2ba0396f04df399c1f685aacced84128518.tar.gz
libvt100-bd9fc2ba0396f04df399c1f685aacced84128518.zip
properly handle zero width characters
Diffstat (limited to 'src/unicode-extra.c')
-rw-r--r--src/unicode-extra.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/unicode-extra.c b/src/unicode-extra.c
index f94aed7..69e5c76 100644
--- a/src/unicode-extra.c
+++ b/src/unicode-extra.c
@@ -65,9 +65,31 @@ static struct vt100_char_range vt100_wide_emoji[] = {
{ 0x1F9C0, 0x1F9C0 },
};
+static int vt100_is_zero_width(uint32_t codepoint);
+static int vt100_is_wide_char(uint32_t codepoint);
static int vt100_is_wide_emoji(uint32_t codepoint);
-int vt100_is_wide_char(uint32_t codepoint)
+int vt100_char_width(uint32_t codepoint)
+{
+ if (vt100_is_zero_width(codepoint)) {
+ return 0;
+ }
+ else if (vt100_is_wide_char(codepoint)) {
+ return 2;
+ }
+ else {
+ return 1;
+ }
+}
+
+static int vt100_is_zero_width(uint32_t codepoint)
+{
+ /* we want soft hyphens to actually be zero width, because terminals don't
+ * do word wrapping */
+ return g_unichar_iszerowidth(codepoint) || codepoint == 0xAD;
+}
+
+static int vt100_is_wide_char(uint32_t codepoint)
{
return g_unichar_iswide(codepoint) || vt100_is_wide_emoji(codepoint);
}