diff -r 1540e501785f -r c712d09cc839 src/eric7/Utilities/__init__.py --- a/src/eric7/Utilities/__init__.py Fri Dec 22 11:04:32 2023 +0100 +++ b/src/eric7/Utilities/__init__.py Fri Dec 22 13:57:47 2023 +0100 @@ -1090,7 +1090,7 @@ def unslash(txt): """ - Function to convert a string containg escape codes to an escaped string. + Function to convert a string containing escape codes to an escaped string. @param txt string to be converted @type str @@ -1152,6 +1152,36 @@ return "".join(s) +_slashmap = {i: hex(i).replace("0x", "\\x") for i in range(7)} +_slashmap.update( + { + 7: "\\a", + 8: "\\b", + 9: "\\t", + 10: "\\n", + 11: "\\v", + 12: "\\f", + 13: "\\r", + } +) +_slashmap.update({i: hex(i).replace("0x", "\\x") for i in range(14, 32)}) +_slashmap.update({i: hex(i).replace("0x", "\\x") for i in range(127, 160)}) + + +def slash(txt): + """ + Function to convert an escaped string to a string containing escape codes. + + Note: This is the reverse of 'unslash()'. + + @param txt string to be converted + @type str + @return converted string containing escaped escape codes + @rtype str + """ + return txt.translate(_slashmap) + + ############################################################################### ## Other utility functions below ###############################################################################