Tizen 2.1 base
[framework/uifw/ecore.git] / src / lib / ecore_input / ecore_input_compose.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif
4
5 #include <stdio.h>
6 #include <string.h>
7
8 #include "Ecore.h"
9 #include "ecore_private.h"
10
11 #include "Ecore_Input.h"
12 #include "ecore_input_private.h"
13
14 // some info on a big big big compose table
15 // http://cgit.freedesktop.org/xorg/lib/libX11/plain/nls/en_US.UTF-8/Compose.pre
16 // isolate compose tree into its own file - hand crafted into static const c
17 #include "ecore_input_compose.h"
18
19 EAPI Ecore_Compose_State
20 ecore_compose_get(const Eina_List *seq, char **seqstr_ret)
21 {
22    Comp *c, *cend;
23    Eina_List *l;
24    const char *s;
25    int i = 0;
26
27    if (!seq) return ECORE_COMPOSE_NONE;
28    l = (Eina_List *)seq;
29    s = l->data;
30    cend = (Comp *)comp + (sizeof(comp) / sizeof(comp[0]));
31    for (c = (Comp *)comp; c->s && s;)
32      {
33         // doesn't match -> jump to next level entry
34         if (!(!strcmp(s, c->s)))
35           {
36              c += c->jump + 1;
37              if (c >= cend)
38                {
39                   return ECORE_COMPOSE_NONE;
40                }
41           }
42         else
43           {
44              cend = c + c->jump;
45              // advance to next sequence member
46              l = l->next;
47              i++;
48              if (l) s = l->data;
49              else s = NULL;
50              c++;
51              // if advanced item jump is an endpoint - it's the string we want
52              if (c->jump == 0)
53                {
54                   if (seqstr_ret) *seqstr_ret = strdup(c->s);
55                   return ECORE_COMPOSE_DONE;
56                }
57           }
58      }
59    if (i == 0) return ECORE_COMPOSE_NONE;
60    return ECORE_COMPOSE_MIDDLE;
61 }