diff options
author | Shawn Landden <shawn@churchofgit.com> | 2013-09-20 18:37:33 -0700 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-10-13 17:56:54 -0400 |
commit | f405e86de361ec305dc2b8634efeaa23dc144053 (patch) | |
tree | b3fe37e4a143a5d2dee14eb34d96f96cb03b84fc /src/shared/gunicode.h | |
parent | 14a9283eb38a93ec384c322ccbe06352c86a25f8 (diff) |
util, utf8: make ellipsize take multi-byte characters into account
rename old versions to ascii_*
Do not take into account zerowidth characters, but do consider double-wide characters.
Import needed utf8 helper code from glib.
v3: rebase ontop of utf8 restructuring work
[zj: tweak the algorithm a bit, move new code to separate file]
Diffstat (limited to 'src/shared/gunicode.h')
-rw-r--r-- | src/shared/gunicode.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/shared/gunicode.h b/src/shared/gunicode.h new file mode 100644 index 0000000000..a4b2934a4b --- /dev/null +++ b/src/shared/gunicode.h @@ -0,0 +1,28 @@ +/* gunicode.h - Unicode manipulation functions + * + * Copyright (C) 1999, 2000 Tom Tromey + * Copyright 2000, 2005 Red Hat, Inc. + */ + +#include <stdint.h> +#include <stdbool.h> +#include <stdlib.h> + +char *utf8_prev_char (const char *p); + +extern const char utf8_skip_data[256]; + +/** + * g_utf8_next_char: + * @p: Pointer to the start of a valid UTF-8 character + * + * Skips to the next character in a UTF-8 string. The string must be + * valid; this macro is as fast as possible, and has no error-checking. + * You would use this macro to iterate over a string character by + * character. The macro returns the start of the next UTF-8 character. + * Before using this macro, use g_utf8_validate() to validate strings + * that may contain invalid UTF-8. + */ +#define utf8_next_char(p) (char *)((p) + utf8_skip_data[*(const unsigned char *)(p)]) + +bool unichar_iswide (uint32_t c); |