MCPcopy Index your code
hub / github.com/RustPython/RustPython / utf_32_decode

Function utf_32_decode

Lib/_pycodecs.py:601–626  ·  view source on GitHub ↗

UTF-32 decoding with BOM detection.

(data, errors="strict", final=0)

Source from the content-addressed store, hash-verified

599
600
601def utf_32_decode(data, errors="strict", final=0):
602 """UTF-32 decoding with BOM detection."""
603 if len(data) >= 4:
604 # Check for BOM
605 if data[0:4] == b"\xff\xfe\x00\x00":
606 # UTF-32 LE BOM
607 res, consumed, _ = PyUnicode_DecodeUTF32Stateful(
608 data[4:], len(data) - 4, errors, "little", final
609 )
610 res = "".join(res)
611 return res, consumed + 4
612 elif data[0:4] == b"\x00\x00\xfe\xff":
613 # UTF-32 BE BOM
614 res, consumed, _ = PyUnicode_DecodeUTF32Stateful(
615 data[4:], len(data) - 4, errors, "big", final
616 )
617 res = "".join(res)
618 return res, consumed + 4
619
620 # Default to little-endian if no BOM
621 byteorder = "little" if sys.byteorder == "little" else "big"
622 res, consumed, _ = PyUnicode_DecodeUTF32Stateful(
623 data, len(data), errors, byteorder, final
624 )
625 res = "".join(res)
626 return res, consumed
627
628
629def utf_32_le_decode(data, errors="strict", final=0):

Callers

nothing calls this directly

Calls 3

lenFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected