summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 127980b)
raw | patch | inline | side by side (parent: 127980b)
author | Max Kellermann <max@duempel.org> | |
Mon, 2 Nov 2009 21:54:41 +0000 (22:54 +0100) | ||
committer | Max Kellermann <max@duempel.org> | |
Mon, 2 Nov 2009 21:54:41 +0000 (22:54 +0100) |
This function is a rather expensive wrapper: it converts the string to
UTF-8 and calls utf8_width().
UTF-8 and calls utf8_width().
src/charset.c | patch | blob | history | |
src/charset.h | patch | blob | history |
diff --git a/src/charset.c b/src/charset.c
index 8e7ed0f0bba6efac5f98aefa44467b11a01d50a5..6282fbf35167cc7015dafd7822c486934809a0b2 100644 (file)
--- a/src/charset.c
+++ b/src/charset.c
#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(str);
+#endif
+}
+
static inline unsigned
ascii_cut_width(char *p, unsigned max_width)
{
diff --git a/src/charset.h b/src/charset.h
index e64eb19adad66c0fdf0d70959b903215600e6b94..651522939e1c216abf563cce59b1aed243c9a7d8 100644 (file)
--- a/src/charset.h
+++ b/src/charset.h
unsigned
utf8_width(const char *str);
+/**
+ * Returns the number of terminal cells occupied by this string.
+ */
+G_GNUC_PURE
+unsigned
+locale_width(const char *p);
+
/**
* Limits the width of the specified string. Cuts it off before the
* specified width is exceeded.