Coverage Report

Created: 2025-03-18 06:55

/src/gnutls/lib/unistring/uninorm/composition.c
Line
Count
Source
1
/* Canonical composition of Unicode characters.
2
   Copyright (C) 2002, 2006, 2009, 2011-2025 Free Software Foundation, Inc.
3
   Written by Bruno Haible <bruno@clisp.org>, 2009.
4
5
   This file is free software: you can redistribute it and/or modify
6
   it under the terms of the GNU Lesser General Public License as
7
   published by the Free Software Foundation; either version 2.1 of the
8
   License, or (at your option) any later version.
9
10
   This file 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
13
   GNU 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 <https://www.gnu.org/licenses/>.  */
17
18
#include <config.h>
19
20
/* Specification.  */
21
#include "uninorm.h"
22
23
#include <string.h>
24
25
struct composition_rule { char codes[6]; unsigned int combined; };
26
27
#include "composition-table.h"
28
#include "composition-table-bounds.h"
29
30
ucs4_t
31
uc_composition (ucs4_t uc1, ucs4_t uc2)
32
1.78M
{
33
1.78M
  if (uc1 <= UNINORM_COMPOSE_MAX_ARG1 && uc2 <= UNINORM_COMPOSE_MAX_ARG2)
34
1.77M
    {
35
1.77M
      if (uc2 >= 0x1161 && uc2 < 0x1161 + 21
36
1.77M
          && uc1 >= 0x1100 && uc1 < 0x1100 + 19)
37
3.44k
        {
38
          /* Hangul: Combine single letter L and single letter V to form
39
             two-letter syllable LV.  */
40
3.44k
          return 0xAC00 + ((uc1 - 0x1100) * 21 + (uc2 - 0x1161)) * 28;
41
3.44k
        }
42
1.76M
      else if (uc2 > 0x11A7 && uc2 < 0x11A7 + 28
43
1.76M
               && uc1 >= 0xAC00 && uc1 < 0xD7A4 && ((uc1 - 0xAC00) % 28) == 0)
44
3.10k
        {
45
          /* Hangul: Combine two-letter syllable LV with single-letter T
46
             to form three-letter syllable LVT.  */
47
3.10k
          return uc1 + (uc2 - 0x11A7);
48
3.10k
        }
49
1.76M
      else
50
1.76M
        {
51
#if 0
52
          unsigned int uc = MUL1 * uc1 * MUL2 * uc2;
53
          unsigned int index1 = uc >> composition_header_0;
54
          if (index1 < composition_header_1)
55
            {
56
              int lookup1 = u_composition.level1[index1];
57
              if (lookup1 >= 0)
58
                {
59
                  unsigned int index2 = (uc >> composition_header_2) & composition_header_3;
60
                  int lookup2 = u_composition.level2[lookup1 + index2];
61
                  if (lookup2 >= 0)
62
                    {
63
                      unsigned int index3 = (uc & composition_header_4);
64
                      unsigned int lookup3 = u_composition.level3[lookup2 + index3];
65
                      if ((lookup3 >> 16) == uc2)
66
                        return lookup3 & ((1U << 16) - 1);
67
                    }
68
                }
69
            }
70
#else
71
1.76M
          char codes[6];
72
1.76M
          const struct composition_rule *rule;
73
74
1.76M
          codes[0] = (uc1 >> 16) & 0xff;
75
1.76M
          codes[1] = (uc1 >> 8) & 0xff;
76
1.76M
          codes[2] = uc1 & 0xff;
77
1.76M
          codes[3] = (uc2 >> 16) & 0xff;
78
1.76M
          codes[4] = (uc2 >> 8) & 0xff;
79
1.76M
          codes[5] = uc2 & 0xff;
80
81
1.76M
          rule = gl_uninorm_compose_lookup (codes, 6);
82
1.76M
          if (rule != NULL)
83
94.3k
            return rule->combined;
84
1.76M
#endif
85
1.76M
        }
86
1.77M
    }
87
1.68M
  return 0;
88
1.78M
}