encoding.utf32 #
utf32
utf32 encodes and decodes UTF-32 (one u32 per code point).
Use encode and decode for []u32 code units. Use encode_le, encode_be, decode_le, and decode_be for little-endian or big-endian byte sequences. The byte decoders return an error when the input length is not a multiple of four.
decode and the byte decoders replace surrogates (U+D800 through U+DFFF) and values above U+10FFFF with U+FFFD. encode replaces malformed UTF-8 in the same way as string.runes().
The endian-specific functions do not add, remove, or detect a byte order mark. U+FEFF and embedded NUL characters are preserved, and the selected function determines the byte order.
import encoding.utf32
units := utf32.encode('V 😀')
assert utf32.decode(units) == 'V 😀'
assert utf32.encode_le('A') == [u8(0x41), 0, 0, 0]
assert utf32.decode_be([u8(0), 0, 0, 0x41])! == 'A'
fn decode #
fn decode(units []u32) string
decode converts UTF-32 code units to a string. Invalid code points are replaced with U+FFFD.
fn decode_be #
fn decode_be(bytes []u8) !string
decode_be decodes big-endian UTF-32 bytes into a string. The byte length must be a multiple of four. Invalid code points are replaced with U+FFFD, and a leading U+FEFF is preserved.
fn decode_le #
fn decode_le(bytes []u8) !string
decode_le decodes little-endian UTF-32 bytes into a string. The byte length must be a multiple of four. Invalid code points are replaced with U+FFFD, and a leading U+FEFF is preserved.
fn encode #
fn encode(s string) []u32
encode returns the UTF-32 code units of s (one u32 per code point). Malformed UTF-8 is replaced with U+FFFD as in string.runes().
fn encode_be #
fn encode_be(s string) []u8
encode_be returns the big-endian byte representation of s.
fn encode_le #
fn encode_le(s string) []u8
encode_le returns the little-endian byte representation of s.