--- a/src/eric7/Utilities/__init__.py Tue Dec 19 09:31:02 2023 +0100 +++ b/src/eric7/Utilities/__init__.py Tue Dec 19 11:04:03 2023 +0100 @@ -1029,6 +1029,68 @@ return match.start() +def unslash(txt): + """ + Function to convert a string containg escape codes to an escaped string. + + @param txt string to be converted + @type str + @return converted string containing escape codes + @rtype str + """ + s = [] + index = 0 + while index < len(txt): + c = txt[index] + if c == "\\" and index + 1 < len(txt): + index += 1 + c = txt[index] + if c == "a": + o = "\a" + elif c == "b": + o = "\b" + elif c == "f": + o = "\f" + elif c == "n": + o = "\n" + elif c == "r": + o = "\r" + elif c == "t": + o = "\t" + elif c == "v": + o = "\v" + elif c in "01234567": + # octal + oc = c + if index + 1 < len(txt) and txt[index + 1] in "01234567": + index += 1 + oc += txt[index] + if index + 1 < len(txt) and txt[index + 1] in "01234567": + index += 1 + oc += txt[index] + o = chr(int(oc, base=8)) + elif c.lower() == "x": + index += 1 + val = 0 + if index < len(txt) and txt[index] in "0123456789abcdefABCDEF": + hx = txt[index] + index += 1 + if index < len(txt) and txt[index] in "0123456789abcdefABCDEF": + hx += txt[index] + index += 1 + val = int(hx, base=16) + o = chr(val) + else: + o = c + else: + o = c + + s.append(o) + index += 1 + + return "".join(s) + + ############################################################################### ## Other utility functions below ###############################################################################