3 # Script to generate libcpp/combining-chars.inc
5 # This file is part of GCC.
7 # GCC is free software; you can redistribute it and/or modify it under
8 # the terms of the GNU General Public License as published by the Free
9 # Software Foundation; either version 3, or (at your option) any later
12 # GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 # You should have received a copy of the GNU General Public License
18 # along with GCC; see the file COPYING3. If not see
19 # <http://www.gnu.org/licenses/>. */
21 from pprint
import pprint
24 def is_combining_char(code_point
) -> bool:
25 return unicodedata
.combining(chr(code_point
)) != 0
28 def __init__(self
, start
, end
, value
):
34 return f
'Range({self.start:x}, {self.end:x}, {self.value})'
36 def make_ranges(value_callback
):
38 for code_point
in range(0x10FFFF):
39 value
= is_combining_char(code_point
)
41 print(f
'{code_point=:x} {value=}')
42 if ranges
and ranges
[-1].value
== value
:
43 # Extend current range
44 ranges
[-1].end
= code_point
47 ranges
.append(Range(code_point
, code_point
, value
))
50 ranges
= make_ranges(is_combining_char
)
54 print(f
"/* Generated by contrib/unicode/gen-combining-chars.py")
55 print(f
" using version {unicodedata.unidata_version}"
56 " of the Unicode standard. */")
57 print("\nstatic const cppchar_t combining_range_ends[] = {", end
="")
58 for i
, r
in enumerate(ranges
):
63 print("0x%x," % r
.end
, end
="")
65 print("static const bool is_combining[] = {", end
="")
66 for i
, r
in enumerate(ranges
):