3 # Script to generate libcpp/printable-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_printable_char(code_point
) -> bool:
25 category
= unicodedata
.category(chr(code_point
))
26 # "Cc" is "control" and "Cf" is "format"
27 return category
[0] != 'C'
30 def __init__(self
, start
, end
, value
):
36 return f
'Range({self.start:x}, {self.end:x}, {self.value})'
38 def make_ranges(value_callback
):
40 for code_point
in range(0x10FFFF):
41 value
= is_printable_char(code_point
)
43 print(f
'{code_point=:x} {value=}')
44 if ranges
and ranges
[-1].value
== value
:
45 # Extend current range
46 ranges
[-1].end
= code_point
49 ranges
.append(Range(code_point
, code_point
, value
))
52 ranges
= make_ranges(is_printable_char
)
56 print(f
"/* Generated by contrib/unicode/gen-printable-chars.py")
57 print(f
" using version {unicodedata.unidata_version}"
58 " of the Unicode standard. */")
59 print("\nstatic const cppchar_t printable_range_ends[] = {", end
="")
60 for i
, r
in enumerate(ranges
):
65 print("0x%x," % r
.end
, end
="")
67 print("static const bool is_printable[] = {", end
="")
68 for i
, r
in enumerate(ranges
):