def dosomething ( str ) :
xxx = ''
i = 0
while i < len( str ) :
#
# Python里字符不再自动等于字节,是两种数据类型。
#
if '\' != str[i] :
xxx += str[i]
else :
#
# Python的字符串没有结尾的NUL字符,务必注意这点
#
if i + 1 >= len( str ) :
#
# 最后一个
#
xxx += str[i]
elif '\' == str[i+1] :
#
# 出现了两个
#
xxx += '\'
i += 1
elif 'r' == str[i+1] :
#
# 出现了\r
#
xxx += '\r'
i += 1
elif 'n' == str[i+1] :
#
# 出现了\n
#
xxx += '\n'
i += 1
elif 't' == str[i+1] :
#
# 出现了\t
#
xxx += '\t'
i += 1
elif '0' == str[i+1] :
#
# 出现了\0
#
xxx += '\0'
i += 1
elif 'x' == str[i+1] :
#
# 出现了\x
#
if ( str[i+2] >= '0' and str[i+2] <= '9' ) or ( str[i+2] >= 'a' and str[i+2] <= 'f' ) or ( str[i+2] >= 'A' and str[i+2] <= 'F' ) :
i += 2
tmp = str[i]
if ( str[i+1] >= '0' and str[i+1] <= '9' ) or ( str[i+1] >= 'a' and str[i+1] <= 'f' ) or ( str[i+1] >= 'A' and str[i+1] <= 'F' ) :
i += 1
tmp += str[i]
else :
tmp = '0' + tmp
#
# 按16进制串处理
#
xxx += tmp.decode( 'hex_codec' )
else :
xxx += str[i]
else :
#
# 无需转义
#
xxx += str[i]
#
# end of switch
#
#
# end of else
#
i += 1
#
# end of while
#
return( xxx )