Oct-14-2016, 08:59 AM
i was hoping it was usable in python 2. i guess i will have to get this old code cleaned up and use it..
#----------------------------------------------------------------------------- # function decode_control # # purpose Decode control characters and other character formatted stuff # in ASCII strings. # # argument string with encoded control characters # # returns string with decoded control characters # # note \a or ^g = alarm # \b or ^h = backspace # \t or ^i = tab # \n or ^j = newline # \v or ^k = vertical tab # \f or ^l = formfeed # \r or ^m = carriage return # \e or ^[ = escape # \\ = literal backslash # ^^ = literal carat # \0 = raw zero (warning: may cause string problems) # \[0-3][0-7][0-7] converts octal to raw # \x[0-9a-fA-F][0-9a-fA-F] converts hexadecimal to raw #----------------------------------------------------------------------------- def decode_control( istr ): b = {'a':7,'b':8,'t':9,'n':10,'v':11,'f':12,'r':13,'e':27,'\\':92,} ostr = '' while len(istr) > 0: c = istr[0] if c == '^': if len(istr) < 2: return ostr c = istr[1] istr = istr[2:] if c == '^': ostr += '^' continue ostr += chr( ord( c ) % 32 ) elif c == '\\': if len(istr) < 2: return ostr c = istr[1] if c in b: ostr += chr(b[c]) istr = istr[2:] continue if len(istr) < 4: return ostr if istr[1] == 'x' or istr[1] == 'X': try: c = int( istr[2:4], 16 ) istr = istr[4:] except: if istr[1] == '0': c = ord( istr[1] ) else: c = 0 istr = istr[2:] else: try: c = int( istr[1:3], 8 ) istr = istr[4:] except: if istr[1] == '0': c = ord( istr[1] ) else: c = 0 istr = istr[2:] ostr += chr( c ) else: ostr += istr[0] istr = istr[1:] return ostr
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply