diff --git a/src/charset.c b/src/charset.c
index 8e7ed0f0bba6efac5f98aefa44467b11a01d50a5..7e2e2d1aeffa5acbacc2f67dd3ad1d7be91dee0e 100644 (file)
--- a/src/charset.c
+++ b/src/charset.c
/* ncmpc (Ncurses MPD Client)
- * (c) 2004-2009 The Music Player Daemon Project
+ * (c) 2004-2010 The Music Player Daemon Project
* Project homepage: http://musicpd.org
* This program is free software; you can redistribute it and/or modify
}
#endif
+#ifdef ENABLE_WIDE
+static inline unsigned
+unicode_char_width(gunichar ch)
+{
+#if GLIB_CHECK_VERSION(2,14,0)
+ if (g_unichar_iszerowidth(ch))
+ return 0;
+#endif
+
+ if (g_unichar_iswide(ch))
+ return 2;
+
+ return 1;
+}
+#endif /* ENABLE_WIDE */
+
unsigned
utf8_width(const char *str)
{
while (len--) {
c = g_utf8_get_char(str);
- width += g_unichar_iswide(c) ? 2 : 1;
+ width += unicode_char_width(c);
str += g_unichar_to_utf8(c, NULL);
}
#endif
}
+unsigned
+locale_width(const char *p)
+{
+#if defined(ENABLE_LOCALE) && defined(ENABLE_MULTIBYTE)
+ char *utf8;
+ unsigned width;
+
+ if (noconvert)
+ return utf8_width(p);
+
+ utf8 = locale_to_utf8(p);
+ width = utf8_width(utf8);
+ g_free(utf8);
+
+ return width;
+#else
+ return strlen(p);
+#endif
+}
+
static inline unsigned
ascii_cut_width(char *p, unsigned max_width)
{