From 3de7b59f8073d1874ae14b23c0b191451f3db788 Mon Sep 17 00:00:00 2001 From: itsme Date: Wed, 7 Jul 2021 18:25:48 +0200 Subject: hexdump: added 'strescape' function --- hexdump.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hexdump.py b/hexdump.py index aeb8c88..cbba3c9 100644 --- a/hexdump.py +++ b/hexdump.py @@ -32,3 +32,13 @@ def hexdump(ofs, data): def tohex(data): return b2a_hex(data).decode('ascii') + +def strescape(txt): + if type(txt)==bytes: + txt = txt.decode('cp1251') + txt = txt.replace("\\", "\\\\") + txt = txt.replace("\n", "\\n") + txt = txt.replace("\r", "\\r") + txt = txt.replace("\t", "\\t") + txt = txt.replace("\"", "\\\"") + return txt -- cgit v1.2.3