diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2018-08-09 15:58:45 -0700 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2018-08-09 15:58:45 -0700 |
| commit | 24e53ad5911f42efb6508b4a8dcf4a196a81494a (patch) | |
| tree | bfbf32aed1e05a27d3e6521353ca052b08a44744 /py/makeqstrdata.py | |
| parent | 1835f1ab14d2532684224d1eccaa5d219b296878 (diff) | |
Rework escaping and fix ESP build.
Diffstat (limited to 'py/makeqstrdata.py')
| -rw-r--r-- | py/makeqstrdata.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py index fd41e3b0e..4be71a8d9 100644 --- a/py/makeqstrdata.py +++ b/py/makeqstrdata.py @@ -54,6 +54,18 @@ codepoint2name[ord('^')] = 'caret' codepoint2name[ord('|')] = 'pipe' codepoint2name[ord('~')] = 'tilde' +C_ESCAPES = { + "\a": "\\a", + "\b": "\\b", + "\f": "\\f", + "\n": "\\r", + "\r": "\\r", + "\t": "\\t", + "\v": "\\v", + "\'": "\\'", + "\"": "\\\"" +} + # this must match the equivalent function in qstr.c def compute_hash(qstr, bytes_hash): hash = 5381 @@ -66,7 +78,13 @@ def translate(translation_file, i18ns): with open(translation_file, "rb") as f: table = gettext.GNUTranslations(f) - return [(x, table.gettext(x.decode('string_escape'))) for x in i18ns] + translations = [] + for original in i18ns: + unescaped = original + for s in C_ESCAPES: + unescaped = unescaped.replace(C_ESCAPES[s], s) + translations.append((original, table.gettext(unescaped))) + return translations def qstr_escape(qst): def esc_char(m): @@ -182,7 +200,9 @@ def print_qstr_data(qcfgs, qstrs, i18ns): total_text_size = 0 for original, translation in i18ns: # Add in carriage returns to work in terminals - translation = translation.replace("\n", "\\r\\n") + translation = translation.replace("\n", "\r\n") + for s in C_ESCAPES: + translation = translation.replace(s, C_ESCAPES[s]) print("TRANSLATION(\"{}\", \"{}\")".format(original, translation)) total_text_size += len(translation) |
