1 /* Decomposition of Unicode characters.
2 Copyright (C) 2009-2024 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2009.
5 This file is free software.
6 It is dual-licensed under "the GNU LGPLv3+ or the GNU GPLv2+".
7 You can redistribute it and/or modify it under either
8 - the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation, either version 3, or (at your
10 option) any later version, or
11 - the terms of the GNU General Public License as published by the
12 Free Software Foundation; either version 2, or (at your option)
14 - the same dual license "the GNU LGPLv3+ or the GNU GPLv2+".
16 This file is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License and the GNU General Public License
22 You should have received a copy of the GNU Lesser General Public
23 License and of the GNU General Public License along with this
24 program. If not, see <https://www.gnu.org/licenses/>. */
31 #include "uninorm/decomposition-table.h"
34 uc_decomposition (ucs4_t uc
, int *decomp_tag
, ucs4_t
*decomposition
)
36 if (uc
>= 0xAC00 && uc
< 0xD7A4)
38 /* Hangul syllable. See Unicode standard, chapter 3, section
39 "Hangul Syllable Decomposition", See also the clarification at
40 <https://www.unicode.org/versions/Unicode5.1.0/>, section
41 "Clarification of Hangul Jamo Handling". */
47 *decomp_tag
= UC_DECOMP_CANONICAL
;
56 decomposition
[0] = 0x1100 + l
;
57 decomposition
[1] = 0x1161 + v
;
62 #if 1 /* Return the pairwise decomposition, not the full decomposition. */
63 decomposition
[0] = 0xAC00 + uc
- t
; /* = 0xAC00 + (l * 21 + v) * 28; */
64 decomposition
[1] = 0x11A7 + t
;
73 decomposition
[0] = 0x1100 + l
;
74 decomposition
[1] = 0x1161 + v
;
75 decomposition
[2] = 0x11A7 + t
;
80 else if (uc
< 0x110000)
82 unsigned short entry
= decomp_index (uc
);
83 if (entry
!= (unsigned short)(-1))
85 const unsigned char *p
;
89 p
= &gl_uninorm_decomp_chars_table
[3 * (entry
& 0x7FFF)];
90 element
= (p
[0] << 16) | (p
[1] << 8) | p
[2];
91 /* The first element has 5 bits for the decomposition type. */
92 *decomp_tag
= (element
>> 18) & 0x1f;
96 /* Every element has an 18 bits wide Unicode code point. */
97 *decomposition
= element
& 0x3ffff;
98 /* Bit 23 tells whether there are more elements, */
99 if ((element
& (1 << 23)) == 0)
102 element
= (p
[0] << 16) | (p
[1] << 8) | p
[2];