Skip to content

Commit f30b6f0

Browse files
committed
py/makeqstrdata: Add more names for escaped chars and esc non-printable.
Non-printable characters are escaped as 0xXX, where XX are the hex digits of the character value.
1 parent 59a4fee commit f30b6f0

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

py/makeqstrdata.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
codepoint2name[ord(',')] = 'comma'
2424
codepoint2name[ord('.')] = 'dot'
2525
codepoint2name[ord(':')] = 'colon'
26+
codepoint2name[ord(';')] = 'semicolon'
2627
codepoint2name[ord('/')] = 'slash'
2728
codepoint2name[ord('%')] = 'percent'
2829
codepoint2name[ord('#')] = 'hash'
@@ -36,6 +37,13 @@
3637
codepoint2name[ord('!')] = 'bang'
3738
codepoint2name[ord('\\')] = 'backslash'
3839
codepoint2name[ord('+')] = 'plus'
40+
codepoint2name[ord('$')] = 'dollar'
41+
codepoint2name[ord('=')] = 'equals'
42+
codepoint2name[ord('?')] = 'question'
43+
codepoint2name[ord('@')] = 'at_sign'
44+
codepoint2name[ord('^')] = 'caret'
45+
codepoint2name[ord('|')] = 'pipe'
46+
codepoint2name[ord('~')] = 'tilde'
3947

4048
# this must match the equivalent function in qstr.c
4149
def compute_hash(qstr, bytes_hash):
@@ -46,7 +54,14 @@ def compute_hash(qstr, bytes_hash):
4654
return (hash & ((1 << (8 * bytes_hash)) - 1)) or 1
4755

4856
def qstr_escape(qst):
49-
return re.sub(r'[^A-Za-z0-9_]', lambda s: "_" + codepoint2name[ord(s.group(0))] + '_', qst)
57+
def esc_char(m):
58+
c = ord(m.group(0))
59+
try:
60+
name = codepoint2name[c]
61+
except KeyError:
62+
name = '0x%02x' % c
63+
return "_" + name + '_'
64+
return re.sub(r'[^A-Za-z0-9_]', esc_char, qst)
5065

5166
def parse_input_headers(infiles):
5267
# read the qstrs in from the input files

0 commit comments

Comments
 (0)