1: #line 260 "utf8.ipk"
2: import string
3:
4: def ucs4le(i):
5: return
6: chr(i & 0xFF) +\
7: chr((i >> 8) & 0xFF) +\
8: chr((i >> 16) & 0xFF) +\
9: chr((i >> 24) & 0xFF)
10:
11: def seq_to_ucs2le(a):
12: s = ''
13: for ch in a: s = s + ucs4le(ch)
14: return s
15:
16:
17: def parse_ucs4le(s, i):
18: return \
19: (ord(s[i+3]) << 24) +\
20: (ord(s[i+2]) << 16) +\
21: (ord(s[i+1]) << 8) +\
22: ord(s[i]) , i+4
23:
24: def ucs4_to_array(s):
25: n = len(s)
26: a = array('H',(0,)*n/4)
27: i = 0
28: while i < n:
29: a[i/4],i = parse_ucs4le(s,i)
30:
31: def ucs4le_to_utf8(s):
32: return seq_to_utf8(ucs4le_to_array(s))
33:
34: