Skip to main content

decode_utf8_char

Function decode_utf8_char 

Source
pub const fn decode_utf8_char(
    bytes: &[u8],
    i: usize,
) -> Result<(char, usize), Utf8Error>
Expand description

Decode an UTF-8 encoded char from the given bytes at offset i.

This function is used by the generated validate_bytes functions.

Examples found in repository?
examples/automata/mod.rs (line 2977)
2973	pub const fn validate_bytes(bytes: &[u8]) -> bool {
2974		let mut i = 0;
2975		let mut automaton = Self::new();
2976		while i < bytes.len() {
2977			match ::static_automata::decode_utf8_char(bytes, i) {
2978				Ok((c, len)) => {
2979					if !automaton.push(c) {
2980						return false;
2981					}
2982					i += len;
2983				}
2984				Err(_) => return false,
2985			}
2986		}
2987		automaton.is_accepting()
2988	}