'''
Created on 2015年2月3日

淨化與清理文字

@author: Guan-yu Willie Chen
'''

import unicodedata
import sys

def sample():
    s = "python\fis\tawesome\r\n"
    
    remap = {
      ord("\t"): ' ',
      ord("\f"): ' ',
      ord("\r"): None         
    }
    
    a = s.translate(remap)
    print(a)
    
def sample1():
    cmbChrs = dict.fromkeys(c for c in range(sys.maxunicode) if unicodedata.combining(chr(c)))
    print(cmbChrs)
    
def sample2():
    digitmap = {c: ord('0')+unicodedata.digit(chr(c))
        for c in range(sys.maxunicode)
        if unicodedata.category(chr(c)) == 'Nd'            
    }
    print(digitmap)
    
    x = "\u0661\u0662\u0663"
    print(x.translate(digitmap))
    
def sample3():
    '''
    最快的清除字串方法
    '''
    
    s = "python\fis\tawesome\r\n"
    
    s = s.replace("\f", ' ')
    s = s.replace("\t", ' ')
    s = s.replace("\r", '')
    
    print(s)
    
if __name__ == '__main__':
    sample()
    sample1()
    sample2()
    sample3()