(fo)
| 33 | |
| 34 | |
| 35 | def parse_hkscs_map(fo): |
| 36 | fo.seek(0, 0) |
| 37 | table = [] |
| 38 | for line in fo: |
| 39 | line = line.split('#', 1)[0].strip() |
| 40 | # We expect 4 columns in supported HKSCS files: |
| 41 | # [1999]: unsupported |
| 42 | # [2001]: unsupported |
| 43 | # [2004]: Big-5; iso10646-1:1993; iso10646-1:2000; iso10646:2003+amd1 |
| 44 | # [2008]: Big-5; iso10646-1:1993; iso10646-1:2000; iso10646:2003+amd6 |
| 45 | # [2016]: not supported here--uses a json file instead |
| 46 | # |
| 47 | # In both supported cases, we only need the first and last column: |
| 48 | # * Big-5 is a hex string (always 4 digits) |
| 49 | # * iso10646:2003 is either a hex string (4 or 5 digits) or a sequence |
| 50 | # of hex strings like: `<code_point1,code_point2>` |
| 51 | try: |
| 52 | hkscs_col, _, _, uni_col = line.split() |
| 53 | hkscs = int(hkscs_col, 16) |
| 54 | seq = tuple(int(cp, 16) for cp in uni_col.strip('<>').split(',')) |
| 55 | except ValueError: |
| 56 | continue |
| 57 | table.append((hkscs, seq)) |
| 58 | return table |
| 59 | |
| 60 | |
| 61 | def make_hkscs_map(table): |
no test coverage detected
searching dependent graphs…