6.5.3. UCS-2le

UCS2LE is a direct byte encoding of the first plane in which the low byte comes first. UCS2 is the standard form, the little endian form is provided only to support files of 16 bit words stored in native byte order on little endian machines such as 80x86 boxes.
Start python section to interscript/encoding/ucs2le.py[1 /1 ]
     1: #line 188 "utf8.ipk"
     2: from array import array
     3: 
     4: # encoding
     5: def ucs2le(i):
     6:   return chr(i & 0xFF)+ chr(i >> 8)
     7: 
     8: def seq_to_ucs2le(a):
     9:   s = ''
    10:   for ch in a: s = s + ucs2le(ch)
    11:   return s
    12: 
    13: # decoding
    14: def parse_ucs2le(s, i):
    15:   return ord(s[i]) + ord(s[i+1]) << 8, i+2
    16: 
    17: def ucs2le_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_ucs2le(s,i)
    23: 
    24: def ucs2le_to_utf8(s):
    25:   return seq_to_utf8(ucs2le_to_array(s))
    26: 
End python section to interscript/encoding/ucs2le.py[1]