blob: b6ec1b6d79060cfa6705dab7dfe4c258da21d304 [file] [log] [blame]
Benjamin Peterson90f5ba52010-03-11 22:53:45 +00001#!/usr/bin/env python3
Skip Montanarof2c47112003-01-01 20:26:47 +00002
3"""
4For each argument on the command line, look for it in the set of all Unicode
5names. Arguments are treated as case-insensitive regular expressions, e.g.:
6
7 % find-uname 'small letter a$' 'horizontal line'
8 *** small letter a$ matches ***
9 LATIN SMALL LETTER A (97)
10 COMBINING LATIN SMALL LETTER A (867)
11 CYRILLIC SMALL LETTER A (1072)
12 PARENTHESIZED LATIN SMALL LETTER A (9372)
13 CIRCLED LATIN SMALL LETTER A (9424)
14 FULLWIDTH LATIN SMALL LETTER A (65345)
15 *** horizontal line matches ***
16 HORIZONTAL LINE EXTENSION (9135)
17"""
18
19import unicodedata
20import sys
21import re
22
23def main(args):
Georg Brandl583350f2009-10-10 22:05:26 +000024 unicode_names = []
Skip Montanarof2c47112003-01-01 20:26:47 +000025 for ix in range(sys.maxunicode+1):
26 try:
Georg Brandl583350f2009-10-10 22:05:26 +000027 unicode_names.append((ix, unicodedata.name(chr(ix))))
Skip Montanarof2c47112003-01-01 20:26:47 +000028 except ValueError: # no name for the character
29 pass
30 for arg in args:
31 pat = re.compile(arg, re.I)
Georg Brandl583350f2009-10-10 22:05:26 +000032 matches = [(y,x) for (x,y) in unicode_names
33 if pat.search(y) is not None]
Skip Montanarof2c47112003-01-01 20:26:47 +000034 if matches:
Collin Winter6f2df4d2007-07-17 20:59:35 +000035 print("***", arg, "matches", "***")
Georg Brandl583350f2009-10-10 22:05:26 +000036 for match in matches:
37 print("%s (%d)" % match)
Skip Montanarof2c47112003-01-01 20:26:47 +000038
39if __name__ == "__main__":
40 main(sys.argv[1:])