1: #line 155 "utf8.ipk" 2: from array import array 3: 4: # encoding 5: def ucs2(i): 6: return chr(i >> 8) + chr(i & 0xFF) 7: 8: def seq_to_ucs2(a): 9: s = '' 10: for ch in a: s = s + ucs2(ch) 11: return s 12: 13: # decoding 14: def parse_ucs2(s, i): 15: return ord(s[i]) << 8 + ord(s[i+1]), i+2 16: 17: def ucs2_to_array(s): 18: n = len(s) 19: a = array('H',(0,)*n/2) 20: i = 0 21: while i < n: 22: a[i/2],i = parse_ucs2(s,i) 23: 24: def ucs2_to_utf8(s): 25: return seq_to_utf8(ucs2_to_array(s)) 26: