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