-
Notifications
You must be signed in to change notification settings - Fork 1
/
layoutlint.py
30 lines (23 loc) · 1008 Bytes
/
layoutlint.py
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
# coding: UTF-8
# license: Public domain.
import re
# Yes, you're thinking “Why is this crazy person using regular expressions to parse an XML file? He should be using xml.dom.minidom.” That was the first thing I tried. Trouble is, it chokes on Ukelele's malformed “<?XML” and on esoteric constructions like “�”. Yeah. So that’s why I’m using regular expressions.
letters = set(u'')
r = re.compile(r'\s*<key code="(\d*)" output="(.*)"/>')
lines = []
usedLetters = set()
with open('Godzilla.PUA.keylayout') as f:
lines = f.readlines()
for line in lines:
m = r.match(line)
if m and m.group(2):
letter = m.group(2)
print letter
letter = unicode(letter, "UTF-8")
usedLetters.add(letter)
else:
print ".",
print
unusedLetters = letters - usedLetters
print unusedLetters
print "Missing {} of {} letters".format(len(unusedLetters), len(letters))