3 # Generate Unicode case-folding table for Ada.
5 # Copyright (C) 2022-2024 Free Software Foundation, Inc.
7 # This file is part of GDB.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # This generates the ada-casefold.h header.
24 # python ada-unicode.py
30 def __init__(self
, range_start
: int, upper_delta
: int, lower_delta
: int):
31 self
._range
_start
= range_start
32 self
._range
_end
= range_start
33 self
._upper
_delta
= upper_delta
34 self
._lower
_delta
= lower_delta
36 # The start of the range.
38 def range_start(self
):
39 return self
._range
_start
41 # The end of the range.
44 return self
._range
_end
47 def range_end(self
, val
: int):
50 # The delta between RANGE_START and the upper-case variant of that
53 def upper_delta(self
):
54 return self
._upper
_delta
56 # The delta between RANGE_START and the lower-case variant of that
59 def lower_delta(self
):
60 return self
._lower
_delta
63 # The current range we are processing. If None, then we're outside of a range.
64 current_range
: Range |
None = None
66 # All the ranges found and completed so far.
67 all_ranges
: list[Range
] = []
73 if current_range
is not None:
74 all_ranges
.append(current_range
)
78 def process_codepoint(val
: int):
84 # U+00DF ("LATIN SMALL LETTER SHARP S", aka eszsett) traditionally
85 # upper-cases to the two-character string "SS" (the capital form
86 # is a relatively recent addition -- 2017). Our simple scheme
87 # can't handle this, so we skip it. Also, because our approach
88 # just represents runs of characters with identical folding
89 # deltas, this change must terminate the current run.
90 if (c
== low
and c
== up
) or len(low
) != 1 or len(up
) != 1:
93 updelta
= ord(up
) - val
94 lowdelta
= ord(low
) - val
96 if current_range
is not None and (
97 updelta
!= current_range
.upper_delta
or lowdelta
!= current_range
.lower_delta
101 if current_range
is None:
102 current_range
= Range(val
, updelta
, lowdelta
)
104 current_range
.range_end
= val
107 for c
in range(0, 0x10FFFF):
110 with
open("ada-casefold.h", "w") as f
:
112 gdbcopyright
.copyright("ada-unicode.py", "UTF-32 case-folding for GDB"),
118 f
" {{{r.range_start}, {r.range_end}, {r.upper_delta}, {r.lower_delta}}},",