File: unicode.py

package info (click to toggle)
ddnet 19.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 68,960 kB
  • sloc: cpp: 195,050; ansic: 58,572; python: 5,568; asm: 946; sh: 941; java: 366; xml: 206; makefile: 31
file content (35 lines) | stat: -rw-r--r-- 852 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import csv

def confusables():
	with open('confusables.txt', encoding='utf-8-sig') as f:
		# Filter comments
		f = map(lambda line: line.split('#')[0], f)
		return list(csv.DictReader(f, fieldnames=['Value', 'Target', 'Category'], delimiter=';'))

UNICODEDATA_FIELDS = (
	"Value",
	"Name",
	"General_Category",
	"Canonical_Combining_Class",
	"Bidi_Class",
	"Decomposition_Type",
	"Decomposition_Mapping",
	"Numeric_Type",
	"Numeric_Mapping",
	"Bidi_Mirrored",
	"Unicode_1_Name",
	"ISO_Comment",
	"Simple_Uppercase_Mapping",
	"Simple_Lowercase_Mapping",
	"Simple_Titlecase_Mapping",
)

def data():
	with open('UnicodeData.txt', encoding='utf-8') as f:
		return list(csv.DictReader(f, fieldnames=UNICODEDATA_FIELDS, delimiter=';'))

def unhex(s):
	return int(s, 16)

def unhex_sequence(s):
	return [unhex(x) for x in s.split()] if '<' not in s else None