xref: /aosp_15_r20/external/hyphenation-patterns/TeX/de/create_chr.py (revision 92a653552b93b47109930ab8dfdbe79e1a46ab29)
1*92a65355Syangbill#!/usr/bin/env python
2*92a65355Syangbill
3*92a65355Syangbill# Copyright (C) 2015 The Android Open Source Project
4*92a65355Syangbill#
5*92a65355Syangbill# Licensed under the Apache License, Version 2.0 (the 'License');
6*92a65355Syangbill# you may not use this file except in compliance with the License.
7*92a65355Syangbill# You may obtain a copy of the License at
8*92a65355Syangbill#
9*92a65355Syangbill#      http://www.apache.org/licenses/LICENSE-2.0
10*92a65355Syangbill#
11*92a65355Syangbill# Unless required by applicable law or agreed to in writing, software
12*92a65355Syangbill# distributed under the License is distributed on an 'AS IS' BASIS,
13*92a65355Syangbill# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*92a65355Syangbill# See the License for the specific language governing permissions and
15*92a65355Syangbill# limitations under the License.
16*92a65355Syangbill
17*92a65355Syangbill"""Generate case mappings from German pattern files."""
18*92a65355Syangbill
19*92a65355Syangbillimport codecs
20*92a65355Syangbill
21*92a65355Syangbillfor locale in ['de-1901', 'de-1996', 'de-ch-1901']:
22*92a65355Syangbill    all_chars = set()
23*92a65355Syangbill    with codecs.open('hyph-%s.pat.txt' % locale, 'r', 'UTF-8') as pat_file:
24*92a65355Syangbill        for line in pat_file:
25*92a65355Syangbill            line = line.strip()
26*92a65355Syangbill            all_chars |= set(line)
27*92a65355Syangbill    all_chars.remove('.')
28*92a65355Syangbill    all_chars -= set('0123456789')
29*92a65355Syangbill
30*92a65355Syangbill    with codecs.open('hyph-%s.chr.txt' % locale, 'w', 'UTF-8') as chr_file:
31*92a65355Syangbill        for c in sorted(all_chars):
32*92a65355Syangbill            # Since Android uses the chr files to map uppercase to lowercase,
33*92a65355Syangbill            # map lowercase sharp s to uppercase sharp s instead of SS.
34*92a65355Syangbill            uppercase = u'\u1E9E' if c == u'\u00DF' else c.upper()
35*92a65355Syangbill            chr_file.write('%s%s\n' % (c, uppercase))
36*92a65355Syangbill
37