Function encoding_c::encoding_for_bom [] [src]

#[no_mangle]
pub unsafe extern "C" fn encoding_for_bom(
    buffer: *const u8,
    buffer_len: *mut usize
) -> *const Encoding

Performs non-incremental BOM sniffing.

The argument must either be a buffer representing the entire input stream (non-streaming case) or a buffer representing at least the first three bytes of the input stream (streaming case).

Returns UTF_8_ENCODING, UTF_16LE_ENCODING or UTF_16BE_ENCODING if the argument starts with the UTF-8, UTF-16LE or UTF-16BE BOM or NULL otherwise. Upon return, *buffer_len is the length of the BOM (zero if there is no BOM).

buffer must be non-NULL even if *buffer_len is zero. When *buffer_len is zero, it is OK for buffer to be something non-dereferencable, such as 0x1. This is required due to Rust's optimization for slices within Option.

Undefined behavior

UB ensues if buffer and *buffer_len don't designate a valid memory block of if buffer is NULL.