6.5.4. UCS-4

UCS4 is a full four byte direct encoding of of ISO-10646. UCS4 puts the high byte first.
Start python section to interscript/encoding/ucs4.py[1 /1 ]
     1: #line 218 "utf8.ipk"
     2: import string
     3: 
     4: def ucs4(i):
     5:   return
     6:     chr((i >> 24) & 0xFF) +\
     7:     chr((i >> 16) & 0xFF) +\
     8:     chr((i >> 8) & 0xFF) +\
     9:     chr(i & 0xFF)
    10: 
    11: def seq_to_ucs4(a):
    12:   s = ''
    13:   for ch in a: s = s + ucs4(ch)
    14:   return s
    15: 
    16: # decoding
    17: def parse_ucs4(s, i):
    18:   return \
    19:     (ord(s[i]) << 24) +\
    20:     (ord(s[i+1]) << 16) +\
    21:     (ord(s[i+2]) << 8)+\
    22:     ord(s[i+3]) , 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_ucs4(s,i)
    30: 
    31: def ucs4_to_utf8(s):
    32:   return seq_to_utf8(ucs4_to_array(s))
    33: 
End python section to interscript/encoding/ucs4.py[1]