summaryrefslogtreecommitdiffstats
path: root/unicode/unicode_emoji.c
diff options
context:
space:
mode:
authorSam Varshavchik2020-07-03 16:50:10 -0400
committerSam Varshavchik2020-07-12 15:56:45 -0400
commit195a98e0dfef34d997a5bca76fac3a81e3ad67bc (patch)
tree79427212117d640814a42f0f94a62412593aff86 /unicode/unicode_emoji.c
parent0c23605497ed7b423169e07c53321877ddf6614b (diff)
downloadcourier-libs-195a98e0dfef34d997a5bca76fac3a81e3ad67bc.tar.bz2
Unicode 13 update.
Diffstat (limited to 'unicode/unicode_emoji.c')
-rw-r--r--unicode/unicode_emoji.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/unicode/unicode_emoji.c b/unicode/unicode_emoji.c
new file mode 100644
index 0000000..9dcd2e6
--- /dev/null
+++ b/unicode/unicode_emoji.c
@@ -0,0 +1,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;
+}