diff options
Diffstat (limited to 'pango/pango-impl-utils.h')
-rw-r--r-- | pango/pango-impl-utils.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/pango/pango-impl-utils.h b/pango/pango-impl-utils.h index a04d4241..3ef3a0c4 100644 --- a/pango/pango-impl-utils.h +++ b/pango/pango-impl-utils.h @@ -122,6 +122,33 @@ pango_utf8_strwidth (const gchar *p) return len; } +/* Glib's g_utf8_strlen() is broken and stops at embedded NUL's. + * Wrap it here. */ +static G_GNUC_UNUSED glong +pango_utf8_strlen (const gchar *p, gssize max) +{ + glong len = 0; + const gchar *start = p; + g_return_val_if_fail (p != NULL || max == 0, 0); + + if (max <= 0) + return g_utf8_strlen (p, max); + + p = g_utf8_next_char (p); + while (p - start < max) + { + ++len; + p = g_utf8_next_char (p); + } + + /* only do the last len increment if we got a complete + * char (don't count partial chars) + */ + if (p - start <= max) + ++len; + + return len; +} G_END_DECLS |