1/* Decomposition of Unicode characters.
2   Copyright (C) 2001-2003, 2009-2010 Free Software Foundation, Inc.
3   Written by Bruno Haible <bruno@clisp.org>, 2009.
4
5   This program is free software: you can redistribute it and/or modify it
6   under the terms of the GNU Lesser General Public License as published
7   by the Free Software Foundation; either version 3 of the License, or
8   (at your option) any later version.
9
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Lesser General Public License for more details.
14
15   You should have received a copy of the GNU Lesser General Public License
16   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18
19#include "unitypes.h"
20
21/* The decomposition table is made of two parts:
22     - A table containing the actual arrays of decomposed equivalents.
23       (This table is separate because the maximum length of a decomposition
24       is 18, much larger than than the average length 1.497 of a decomposition).
25     - A 3-level table of indices into this array.  */
26
27#include "decomposition-table1.h"
28
29static inline unsigned short
30decomp_index (ucs4_t uc)
31{
32  unsigned int index1 = uc >> decomp_header_0;
33  if (index1 < decomp_header_1)
34    {
35      int lookup1 = gl_uninorm_decomp_index_table.level1[index1];
36      if (lookup1 >= 0)
37        {
38          unsigned int index2 = (uc >> decomp_header_2) & decomp_header_3;
39          int lookup2 = gl_uninorm_decomp_index_table.level2[lookup1 + index2];
40          if (lookup2 >= 0)
41            {
42              unsigned int index3 = uc & decomp_header_4;
43              return gl_uninorm_decomp_index_table.level3[lookup2 + index3];
44            }
45        }
46    }
47  return (unsigned short)(-1);
48}
49