Function encoding_c::encoding_for_label [] [src]

#[no_mangle]
pub unsafe extern "C" fn encoding_for_label(
    label: *const u8,
    label_len: usize
) -> *const Encoding

Implements the get an encoding algorithm.

If, after ASCII-lowercasing and removing leading and trailing whitespace, the argument matches a label defined in the Encoding Standard, const Encoding* representing the corresponding encoding is returned. If there is no match, NULL is returned.

This is the right function to use if the action upon the method returning NULL is to use a fallback encoding (e.g. WINDOWS_1252_ENCODING) instead. When the action upon the method returning NULL is not to proceed with a fallback but to refuse processing, encoding_for_label_no_replacement() is more appropriate.

The argument buffer can be in any ASCII-compatible encoding. It is not required to be UTF-8.

label must be non-NULL even if label_len is zero. When label_len is zero, it is OK for label 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 label and label_len don't designate a valid memory block of if label is NULL.