Does Rust provide a way to decode a single character (unicode-scalar-value to be exact) from a &[u8]
, which may be multiple bytes, returning a single USV?
Something like GLib's g_utf8_get_char
& g_utf8_next_char
:
// Example of what glib's functions might look like once ported to Rust.
let i = 0;
while i < slice.len() {
let unicode_char = g_utf8_get_char(&slice[i..]);
// do something with the unicode character
funcion(unicode_char);
// move onto the next.
i += g_utf8_next_char(&slice[i..]);
}
Short of porting parts of the GLib API to Rust, does Rust provide a way to do this, besides some trial & error calls to from_utf8
which stop once the second character is reached?
See GLib's code.