1: #line 77 "johab.ipk" 2: from array import array 3: 4: lead_first1 = 0x81 5: lead_last1 = 0xC6 6: lead_first2 = 0xC7 7: lead_last2 = 0xFD 8: trail_first1 = 0x41 9: trail_first2 = 0xA1 10: trail_last = 0xFE 11: width1 = trail_last - trail_first1 + 1 12: width2 = trail_last - trail_first2 + 1 13: size1 = (lead_last1 - lead_first1 + 1) * width1 14: size2 = (lead_last2 - lead_first1 + 1) * width2 15: kscsize = size1 + size2 16: 17: tou = array('H') 18: filename = 'interscript/encoding/ksc5601-1992.dat' 19: f = open(filename,'rb') 20: tou.fromfile(f,kscsize) 21: f.close() 22: 23: def ksc5601_1992_to_unicode(ch): 24: hi = ch >> 8 25: lo = ch & 0xFF 26: if ch<=0x7F: 27: return ch 28: elif lead_first1 <= hi <= lead_last1 and trail_first1 <= lo <= trail_last: 29: return tou[(hi-lead_first1)*width1+lo-trail_first1] 30: elif lead_first2 <= hi <= lead_last2 and trail_first2 <= lo <= trail_last: 31: return tou[(hi-lead_first2)*width2+lo-trail_first2+size1] 32: else: 33: return 0xFFFF 34: 35: def ksc5601_1992_to_utf8(s): 36: u = '' 37: i = 0 38: n = len(s) 39: while 1: 40: ch = s[i] 41: i = i + 1 42: ch = ch << 8 | s[i] 43: u = u + utf8(ksc5601_1992_to_unicode(ch)) 44: i = i + 1 45: if i==n: break 46: return u 47: