File: unicode_tablookup.c

package info (click to toggle)
cone 0.89-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 25,628 kB
  • ctags: 14,171
  • sloc: ansic: 85,400; cpp: 82,903; sh: 11,713; makefile: 1,732; perl: 832; yacc: 291; sed: 16
file content (49 lines) | stat: -rw-r--r-- 902 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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;
}