summaryrefslogtreecommitdiffstatshomepage
path: root/py/makeqstrdata.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-04-13 22:12:39 +0100
committerDamien George <damien.p.george@gmail.com>2016-04-13 22:12:39 +0100
commitf30b6f0af56c4358909f2a9b9d696a8f4f920f81 (patch)
tree82fc007b48dc74104d4677ea2097c546c83338c7 /py/makeqstrdata.py
parent59a4fee5161c198f59a4a1f7afe4096d23826ab1 (diff)
downloadmicropython-f30b6f0af56c4358909f2a9b9d696a8f4f920f81.tar.gz
micropython-f30b6f0af56c4358909f2a9b9d696a8f4f920f81.zip
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.
Diffstat (limited to 'py/makeqstrdata.py')
-rw-r--r--py/makeqstrdata.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py
index ea0ecd686f..4215ff3017 100644
--- a/py/makeqstrdata.py
+++ b/py/makeqstrdata.py
@@ -23,6 +23,7 @@ codepoint2name[ord('\'')] = 'squot'
codepoint2name[ord(',')] = 'comma'
codepoint2name[ord('.')] = 'dot'
codepoint2name[ord(':')] = 'colon'
+codepoint2name[ord(';')] = 'semicolon'
codepoint2name[ord('/')] = 'slash'
codepoint2name[ord('%')] = 'percent'
codepoint2name[ord('#')] = 'hash'
@@ -36,6 +37,13 @@ codepoint2name[ord('*')] = 'star'
codepoint2name[ord('!')] = 'bang'
codepoint2name[ord('\\')] = 'backslash'
codepoint2name[ord('+')] = 'plus'
+codepoint2name[ord('$')] = 'dollar'
+codepoint2name[ord('=')] = 'equals'
+codepoint2name[ord('?')] = 'question'
+codepoint2name[ord('@')] = 'at_sign'
+codepoint2name[ord('^')] = 'caret'
+codepoint2name[ord('|')] = 'pipe'
+codepoint2name[ord('~')] = 'tilde'
# this must match the equivalent function in qstr.c
def compute_hash(qstr, bytes_hash):
@@ -46,7 +54,14 @@ def compute_hash(qstr, bytes_hash):
return (hash & ((1 << (8 * bytes_hash)) - 1)) or 1
def qstr_escape(qst):
- return re.sub(r'[^A-Za-z0-9_]', lambda s: "_" + codepoint2name[ord(s.group(0))] + '_', qst)
+ def esc_char(m):
+ c = ord(m.group(0))
+ try:
+ name = codepoint2name[c]
+ except KeyError:
+ name = '0x%02x' % c
+ return "_" + name + '_'
+ return re.sub(r'[^A-Za-z0-9_]', esc_char, qst)
def parse_input_headers(infiles):
# read the qstrs in from the input files