#[no_mangle]
pub unsafe extern "C" fn encoding_for_label_no_replacement(
label: *const u8,
label_len: usize,
) -> *const Encoding
Expand description
This function behaves the same as encoding_for_label()
, except when
encoding_for_label()
would return REPLACEMENT_ENCODING
, this method
returns NULL
instead.
This method is useful in scenarios where a fatal error is required upon invalid label, because in those cases the caller typically wishes to treat the labels that map to the replacement encoding as fatal errors, too.
It is not OK to use this funciton when the action upon the method returning
NULL
is to use a fallback encoding (e.g. WINDOWS_1252_ENCODING
). In
such a case, the encoding_for_label()
function should be used instead
in order to avoid unsafe fallback for labels that encoding_for_label()
maps to REPLACEMENT_ENCODING
.
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
.