From e7e86e8a3669e819532428790fd06bc59e8dda70 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Mon, 3 Aug 2020 23:42:09 -0400 Subject: [PATCH] formatting "chars" --- menu.py | 18 +++++++++--------- utils.py | 4 +++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/menu.py b/menu.py index f13f07e..1142d29 100644 --- a/menu.py +++ b/menu.py @@ -33,13 +33,13 @@ _menu_item_ids = {} -def _to_char_string(x): - if not x: return '""' - if x == 0x0d: return "\\n" # intentionally backwards - if x == 0x0a: return "\\r" # - if chr(x) in "\\\\'" : return "\\" + x - if x >= 32 and x < 0x7e: return '"' + chr(x) + '"' - return "\\${:02x}".format(x) +# def _to_char_string(x): +# if not x: return '""' +# if x == 0x0d: return "\\n" # intentionally backwards +# if x == 0x0a: return "\\r" # +# if chr(x) in "\\\\'" : return "\\" + x +# if x >= 32 and x < 0x7e: return '"' + chr(x) + '"' +# return "\\${:02x}".format(x) class rMenuBar(rObject): rName = "rMenuBar" @@ -237,8 +237,8 @@ class rMenuItem(rObject): "\t0x{:04x} /* title ref (rPString) */" ).format( itemID, - _to_char_string(self.itemChar), - _to_char_string(self.altItemChar), + format_char(self.itemChar), + format_char(self.altItemChar), self.checkMark, self.flags, self.title.get_id() diff --git a/utils.py b/utils.py index 4bc4370..7cce101 100644 --- a/utils.py +++ b/utils.py @@ -42,9 +42,11 @@ def format_string(bstring, quote=True): if quote: return '"' + s + '"' return s +# rez "char" is a string of length 1. +# 'x' is character literal which is a number. def format_char(x): c = _map.get(x, chr(x)) - return "'" + c + "'" + return '"' + c + '"' def multi_format_string(bstring, indent=""): q = '"'