mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-03 07:30:56 +00:00
DEVTOOLS: COMPANION: bring escape inline
Original dumper-companion.pl script encoded \x81 to \x81\x79\x81. - added test to check for correct behavior - refactored escape string to handle this special case
This commit is contained in:
parent
a1a31748e8
commit
6e5d7c2395
@ -52,10 +52,14 @@ def file_to_macbin(f: machfs.File, name: str, encoding: str) -> bytes:
|
||||
|
||||
|
||||
def escape_string(s: str) -> str:
|
||||
new_name = [
|
||||
"\x81" + chr(0x80 + ord(i)) if i in '/":*[]+|\\?%<>,;=' or ord(i) < 0x20 else i
|
||||
for i in s
|
||||
]
|
||||
new_name = ""
|
||||
for char in s:
|
||||
if char == "\x81":
|
||||
new_name += "\x81\x79"
|
||||
if char in '/":*[]+|\\?%<>,;=' or ord(char) < 0x20:
|
||||
new_name += "\x81" + chr(0x80 + ord(char))
|
||||
else:
|
||||
new_name += char
|
||||
return "".join(new_name)
|
||||
|
||||
|
||||
@ -190,6 +194,6 @@ def test_decode_name():
|
||||
|
||||
|
||||
def test_escape_string():
|
||||
checks = [["\r", "\x81\x8d"]]
|
||||
checks = [["\r", "\x81\x8d"], ["\x81", "\x81\x79\x81"]]
|
||||
for input, expected in checks:
|
||||
assert escape_string(input) == expected
|
||||
|
Loading…
Reference in New Issue
Block a user