diff options
| author | Sam Varshavchik | 2013-08-19 16:39:41 -0400 | 
|---|---|---|
| committer | Sam Varshavchik | 2013-08-25 14:43:51 -0400 | 
| commit | 9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch) | |
| tree | 7a81a04cb51efb078ee350859a64be2ebc6b8813 /unicode/unicode_tablookup.c | |
| parent | a9520698b770168d1f33d6301463bb70a19655ec (diff) | |
| download | courier-libs-9c45d9ad13fdf439d44d7443ae75da15ea0223ed.tar.bz2 | |
Initial checkin
Imported from subversion report, converted to git. Updated all paths in
scripts and makefiles, reflecting the new directory hierarchy.
Diffstat (limited to 'unicode/unicode_tablookup.c')
| -rw-r--r-- | unicode/unicode_tablookup.c | 49 | 
1 files changed, 49 insertions, 0 deletions
| diff --git a/unicode/unicode_tablookup.c b/unicode/unicode_tablookup.c new file mode 100644 index 0000000..c61526d --- /dev/null +++ b/unicode/unicode_tablookup.c @@ -0,0 +1,49 @@ +/* +** Copyright 2011 Double Precision, Inc. +** See COPYING for distribution information. +** +*/ + +#include	"unicode_config.h" +#include	"unicode.h" + +#define BLOCK_SIZE	256 + +uint8_t unicode_tab_lookup(unicode_char ch, +			   const size_t *unicode_indextab, +			   size_t unicode_indextab_sizeof, +			   const uint8_t (*unicode_rangetab)[2], +			   const uint8_t *unicode_classtab, +			   uint8_t uclass) +{ +	size_t cl=ch / BLOCK_SIZE; + +	if (cl < unicode_indextab_sizeof-1) +	{ +		const size_t start_pos=unicode_indextab[cl]; +		const uint8_t (*p)[2]=unicode_rangetab + start_pos; +		size_t b=0, e=unicode_indextab[cl+1] - start_pos; +		uint8_t chmodcl= ch & (BLOCK_SIZE-1); + +		while (b < e) +		{ +			size_t n=b + (e-b)/2; + +			if (chmodcl >= p[n][0]) +			{ +				if (chmodcl <= p[n][1]) +				{ +					uclass=unicode_classtab[start_pos+n]; +					break; +				} +				b=n+1; +			} +			else +			{ +				e=n; +			} +		} +	} + +	return uclass; +} | 
