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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/*
** Copyright 2011 Double Precision, Inc.
** See COPYING for distribution information.
**
*/
#include "unicode_config.h"
#include "courier-unicode.h"
#include "emojitab.h"
static int emoji_lookup(const char32_t (*p)[2], size_t e, char32_t c)
{
size_t b=0;
while (b < e)
{
size_t n=b + (e-b)/2;
if (c >= p[n][0])
{
if (c <= p[n][1])
{
return 1;
}
b=n+1;
}
else
{
e=n;
}
}
return 0;
}
#define LOOKUP(t) emoji_lookup(t, sizeof(t)/sizeof(t[0]), c)
int unicode_emoji(char32_t c)
{
return LOOKUP(unicode_emoji_emoji_lookup);
}
int unicode_emoji_presentation(char32_t c)
{
return LOOKUP(unicode_emoji_emoji_presentation_lookup);
}
int unicode_emoji_modifier(char32_t c)
{
return LOOKUP(unicode_emoji_emoji_modifier_lookup);
}
int unicode_emoji_modifier_base(char32_t c)
{
return LOOKUP(unicode_emoji_emoji_modifier_base_lookup);
}
int unicode_emoji_component(char32_t c)
{
return LOOKUP(unicode_emoji_emoji_component_lookup);
}
int unicode_emoji_extended_pictographic(char32_t c)
{
return LOOKUP(unicode_emoji_extended_pictographic_lookup);
}
static const struct {
int (*lookup_func)(char32_t);
unicode_emoji_t flag;
} lookups[]={
{ unicode_emoji, UNICODE_EMOJI},
{ unicode_emoji_presentation, UNICODE_EMOJI_PRESENTATION},
{ unicode_emoji_modifier, UNICODE_EMOJI_MODIFIER},
{ unicode_emoji_modifier_base, UNICODE_EMOJI_MODIFIER_BASE},
{ unicode_emoji_component, UNICODE_EMOJI_COMPONENT},
{ unicode_emoji_extended_pictographic,
UNICODE_EMOJI_EXTENDED_PICTOGRAPHIC},
};
extern unicode_emoji_t unicode_emoji_lookup(char32_t c)
{
unicode_emoji_t v=UNICODE_EMOJI_NONE;
for (size_t i=0; i<sizeof(lookups)/sizeof(lookups[0]); ++i)
if ( (*lookups[i].lookup_func)(c) )
v |= lookups[i].flag;
return v;
}
|