diff options
| author | Sam Varshavchik | 2015-07-26 21:34:21 -0400 | 
|---|---|---|
| committer | Sam Varshavchik | 2015-07-26 21:34:21 -0400 | 
| commit | f1bd3147e4df1bda680a7ecbfeca5699eed7788f (patch) | |
| tree | f70a304d7f34ee14277ebe93ac0460d720751a37 /unicode/unicode_categories.c | |
| parent | 19309085193effe5d231fa3c99e8f9c33fdc2b4f (diff) | |
| download | courier-libs-f1bd3147e4df1bda680a7ecbfeca5699eed7788f.tar.bz2 | |
courier-unicode: implement tn36 (unicode_category_lookup).
Diffstat (limited to 'unicode/unicode_categories.c')
| -rw-r--r-- | unicode/unicode_categories.c | 84 | 
1 files changed, 84 insertions, 0 deletions
| diff --git a/unicode/unicode_categories.c b/unicode/unicode_categories.c new file mode 100644 index 0000000..9353dbf --- /dev/null +++ b/unicode/unicode_categories.c @@ -0,0 +1,84 @@ +/* +** Copyright 2015 Double Precision, Inc. +** See COPYING for distribution information. +** +*/ + +#include	"unicode_config.h" +#include	"courier-unicode.h" +#include	"categoriestab.h" +#include	"linebreaktab_internal.h" + +uint32_t unicode_category_lookup(unicode_char ch) +{ +	return unicode_tab32_lookup(ch, +				    unicode_indextab, +				    sizeof(unicode_indextab) +				    / sizeof(unicode_indextab[0]), +				    unicode_rangetab, +				    unicode_classtab, +				    0); +} + +int unicode_isspace(unicode_char ch) +{ +	switch (unicode_lb_lookup(ch)) { +	case UNICODE_LB_BK: +	case UNICODE_LB_CR: +	case UNICODE_LB_LF: +	case UNICODE_LB_NL: +	case UNICODE_LB_SP: +		return 1; +	} + +	return unicode_isblank(ch); +} + +int unicode_isblank(unicode_char ch) +{ +	if (ch == 9) +		return 1; + +	if ((unicode_category_lookup(ch) & UNICODE_CATEGORY_2) == +	    UNICODE_CATEGORY_2_SPACE) +		return 1; +	return 0; +} + +int unicode_isalpha(unicode_char ch) +{ +	return (unicode_category_lookup(ch) & UNICODE_CATEGORY_1) == +		UNICODE_CATEGORY_1_LETTER; +} + +int unicode_isdigit(unicode_char ch) +{ +	return unicode_category_lookup(ch) == +		(UNICODE_CATEGORY_1_NUMBER | UNICODE_CATEGORY_2_DIGIT); +} + +int unicode_isalnum(unicode_char ch) +{ +	return unicode_is_alpha(ch) || unicode_is_digit(ch); +} + +int unicode_isgraph(unicode_char ch) +{ +	return (ch >= ' ' && !unicode_isspace(ch)); +} + +int unicode_ispunct(unicode_char ch) +{ +	return (unicode_category_lookup(ch) & UNICODE_CATEGORY_1) == +		UNICODE_CATEGORY_1_PUNCTUATION; +} + +int unicode_islower(unicode_char ch) +{ +	return unicode_isalpha(ch) && ch == unicode_lc(ch); +} + +int unicode_isupper(unicode_char ch) +{ +	return unicode_isalpha(ch) && ch == unicode_uc(ch); +} | 
