formatting "chars"

This commit is contained in:
Kelvin Sherlock 2020-08-03 23:42:09 -04:00
parent bfb1d296cc
commit e7e86e8a36
2 changed files with 12 additions and 10 deletions

18
menu.py
View File

@ -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()

View File

@ -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 = '"'