1 /* Decomposition of Unicode characters.
2 Copyright (C) 2009-2020 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 <https://www.gnu.org/licenses/>. */
23 #include "uninorm/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, section
31 "Hangul Syllable Decomposition", See also the clarification at
32 <https://www.unicode.org/versions/Unicode5.1.0/>, section
33 "Clarification of Hangul Jamo Handling". */
39 *decomp_tag
= UC_DECOMP_CANONICAL
;
48 decomposition
[0] = 0x1100 + l
;
49 decomposition
[1] = 0x1161 + v
;
54 #if 1 /* Return the pairwise decomposition, not the full decomposition. */
55 decomposition
[0] = 0xAC00 + uc
- t
; /* = 0xAC00 + (l * 21 + v) * 28; */
56 decomposition
[1] = 0x11A7 + t
;
65 decomposition
[0] = 0x1100 + l
;
66 decomposition
[1] = 0x1161 + v
;
67 decomposition
[2] = 0x11A7 + t
;
72 else if (uc
< 0x110000)
74 unsigned short entry
= decomp_index (uc
);
75 if (entry
!= (unsigned short)(-1))
77 const unsigned char *p
;
81 p
= &gl_uninorm_decomp_chars_table
[3 * (entry
& 0x7FFF)];
82 element
= (p
[0] << 16) | (p
[1] << 8) | p
[2];
83 /* The first element has 5 bits for the decomposition type. */
84 *decomp_tag
= (element
>> 18) & 0x1f;
88 /* Every element has an 18 bits wide Unicode code point. */
89 *decomposition
= element
& 0x3ffff;
90 /* Bit 23 tells whether there are more elements, */
91 if ((element
& (1 << 23)) == 0)
94 element
= (p
[0] << 16) | (p
[1] << 8) | p
[2];