11cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader#!/usr/bin/env python
21cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader
31cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader# Copyright (C) 2015 The Android Open Source Project
41cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader#
51cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader# Licensed under the Apache License, Version 2.0 (the 'License');
61cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader# you may not use this file except in compliance with the License.
71cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader# You may obtain a copy of the License at
81cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader#
91cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader#      http://www.apache.org/licenses/LICENSE-2.0
101cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader#
111cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader# Unless required by applicable law or agreed to in writing, software
121cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader# distributed under the License is distributed on an 'AS IS' BASIS,
131cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
141cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader# See the License for the specific language governing permissions and
151cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader# limitations under the License.
161cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader
171cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader"""Generate case mappings from German pattern files."""
181cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader
191cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournaderimport codecs
201cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader
211cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournaderfor locale in ['de-1901', 'de-1996', 'de-ch-1901']:
221cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader    all_chars = set()
231cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader    with codecs.open('hyph-%s.pat.txt' % locale, 'r', 'UTF-8') as pat_file:
241cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader        for line in pat_file:
251cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader            line = line.strip()
261cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader            all_chars |= set(line)
271cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader    all_chars.remove('.')
281cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader    all_chars -= set('0123456789')
291cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader
301cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader    with codecs.open('hyph-%s.chr.txt' % locale, 'w', 'UTF-8') as chr_file:
311cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader        for c in sorted(all_chars):
321cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader            # Since Android uses the chr files to map uppercase to lowercase,
331cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader            # map lowercase sharp s to uppercase sharp s instead of SS.
341cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader            uppercase = u'\u1E9E' if c == u'\u00DF' else c.upper()
351cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader            chr_file.write('%s%s\n' % (c, uppercase))
361cf343118b814f2b44c0fbc9a23d76fb6683faefRoozbeh Pournader
37