From a4c84d2063bb6f2218bc20f89e59001319361f6d Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Sun, 8 Mar 2015 17:23:43 -0400 Subject: fix #2: add charwidth function --- utf8proc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'utf8proc.c') diff --git a/utf8proc.c b/utf8proc.c index 4035876..ff89934 100644 --- a/utf8proc.c +++ b/utf8proc.c @@ -223,6 +223,21 @@ DLLEXPORT bool utf8proc_grapheme_break(int32_t c1, int32_t c2) { utf8proc_get_property(c2)->boundclass); } +/* return a character width analogous to wcwidth (except portable and + hopefully less buggy than most system wcwidth functions). */ +DLLEXPORT int utf8proc_charwidth(int32_t c) { + return utf8proc_get_property(c)->charwidth; +} + +DLLEXPORT int utf8proc_category(int32_t c) { + return utf8proc_get_property(c)->category; +} + +DLLEXPORT const char *utf8proc_category_string(int32_t c) { + static const char s[][3] = {"Cn","Lu","Ll","Lt","Lm","Lo","Mn","Mc","Me","Nd","Nl","No","Pc","Pd","Ps","Pe","Pi","Pf","Po","Sm","Sc","Sk","So","Zs","Zl","Zp","Cc","Cf","Cs","Co"}; + return s[utf8proc_category(c)]; +} + #define utf8proc_decompose_lump(replacement_uc) \ return utf8proc_decompose_char((replacement_uc), dst, bufsize, \ options & ~UTF8PROC_LUMP, last_boundclass) -- cgit v1.2.3