def PyUnicode_DecodeUTF32(space, s, size, llerrors, pbyteorder): """Decode length bytes from a UTF-32 encoded buffer string and return the corresponding Unicode object. errors (if non-NULL) defines the error handling. It defaults to "strict". If byteorder is non-NULL, the decoder starts decoding using the given byte order: *byteorder == -1: little endian *byteorder == 0: native order *byteorder == 1: big endian If *byteorder is zero, and the first four bytes of the input data are a byte order mark (BOM), the decoder switches to this byte order and the BOM is not copied into the resulting Unicode string. If *byteorder is -1 or 1, any byte order mark is copied to the output. After completion, *byteorder is set to the current byte order at the end of input data. In a narrow build codepoints outside the BMP will be decoded as surrogate pairs. If byteorder is NULL, the codec starts in native order mode. Return NULL if an exception was raised by the codec. """ string = rffi.charpsize2str(s, size) if pbyteorder: llbyteorder = rffi.cast(lltype.Signed, pbyteorder[0]) if llbyteorder < 0: byteorder = "little" elif llbyteorder > 0: byteorder = "big" else: byteorder = "native" else: byteorder = "native" if llerrors: errors = rffi.charp2str(llerrors) else: errors = None result, length, byteorder = unicodehelper.str_decode_utf_32_helper( string, size, errors, True, # final ? false for multiple passes? None, # errorhandler byteorder) if pbyteorder is not None: pbyteorder[0] = rffi.cast(rffi.INT_real, byteorder) return space.newunicode(result)
def utf_32_ex_decode(space, data, errors='strict', byteorder=0, w_final=None): from pypy.interpreter.unicodehelper import str_decode_utf_32_helper final = space.is_true(w_final) state = space.fromcache(CodecState) if byteorder == 0: _byteorder = 'native' elif byteorder == -1: _byteorder = 'little' else: _byteorder = 'big' res, lgt, pos, bo = str_decode_utf_32_helper(data, errors, final, state.decode_error_handler, _byteorder) # return result, consumed, byteorder for buffered incremental encoders return space.newtuple( [space.newutf8(res, lgt), space.newint(pos), space.newint(bo)])
def utf_32_ex_decode(space, data, errors='strict', byteorder=0, w_final=None): from pypy.interpreter.unicodehelper import str_decode_utf_32_helper final = space.is_true(w_final) state = space.fromcache(CodecState) if byteorder == 0: byteorder = 'native' elif byteorder == -1: byteorder = 'little' else: byteorder = 'big' consumed = len(data) if final: consumed = 0 res, consumed, lgt, byteorder = str_decode_utf_32_helper( data, errors, final, state.decode_error_handler, byteorder) return space.newtuple([space.newutf8(res, lgt), space.newint(consumed), space.newint(byteorder)])