ยปCore Development>Code coverage>Tools/scripts/find-uname.py

Python code coverage for Tools/scripts/find-uname.py

#countcontent
1n/a#!/usr/bin/env python3
2n/a
3n/a"""
4n/aFor each argument on the command line, look for it in the set of all Unicode
5n/anames. Arguments are treated as case-insensitive regular expressions, e.g.:
6n/a
7n/a % find-uname 'small letter a$' 'horizontal line'
8n/a *** small letter a$ matches ***
9n/a LATIN SMALL LETTER A (97)
10n/a COMBINING LATIN SMALL LETTER A (867)
11n/a CYRILLIC SMALL LETTER A (1072)
12n/a PARENTHESIZED LATIN SMALL LETTER A (9372)
13n/a CIRCLED LATIN SMALL LETTER A (9424)
14n/a FULLWIDTH LATIN SMALL LETTER A (65345)
15n/a *** horizontal line matches ***
16n/a HORIZONTAL LINE EXTENSION (9135)
17n/a"""
18n/a
19n/aimport unicodedata
20n/aimport sys
21n/aimport re
22n/a
23n/adef main(args):
24n/a unicode_names = []
25n/a for ix in range(sys.maxunicode+1):
26n/a try:
27n/a unicode_names.append((ix, unicodedata.name(chr(ix))))
28n/a except ValueError: # no name for the character
29n/a pass
30n/a for arg in args:
31n/a pat = re.compile(arg, re.I)
32n/a matches = [(y,x) for (x,y) in unicode_names
33n/a if pat.search(y) is not None]
34n/a if matches:
35n/a print("***", arg, "matches", "***")
36n/a for match in matches:
37n/a print("%s (%d)" % match)
38n/a
39n/aif __name__ == "__main__":
40n/a main(sys.argv[1:])