1 /* Decomposition of Unicode characters.
2 Copyright (C) 2009 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2009.
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.
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.
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/>. */
23 #include "decomposition-table.h"
26 uc_decomposition (ucs4_t uc, int *decomp_tag, ucs4_t *decomposition)
28 if (uc >= 0xAC00 && uc < 0xD7A4)
30 /* Hangul syllable. See Unicode standard, chapter 3,
31 section "Hangul Syllable Decomposition". */
40 *decomp_tag = UC_DECOMP_CANONICAL;
41 decomposition[0] = 0x1100 + l;
42 decomposition[1] = 0x1161 + v;
47 decomposition[2] = 0x11A7 + t;
51 else if (uc < 0x110000)
53 unsigned short entry = decomp_index (uc);
54 if (entry != (unsigned short)(-1))
56 const unsigned char *p;
60 p = &gl_uninorm_decomp_chars_table[3 * (entry & 0x7FFF)];
61 element = (p[0] << 16) | (p[1] << 8) | p[2];
62 /* The first element has 5 bits for the decomposition type. */
63 *decomp_tag = (element >> 18) & 0x1f;
67 /* Every element has an 18 bits wide Unicode code point. */
68 *decomposition = element & 0x3ffff;
69 /* Bit 23 tells whether there are more elements, */
70 if ((element & (1 << 23)) == 0)
73 element = (p[0] << 16) | (p[1] << 8) | p[2];