Skip to main content

Crate utf8_iter

Crate utf8_iter 

Source
Expand description

Provides iteration by char over &[u8] containing potentially-invalid UTF-8 such that errors are handled according to the WHATWG Encoding Standard (i.e. the same way as in String::from_utf8_lossy).

The trait Utf8CharsEx provides the convenience method chars() on byte slices themselves instead of having to use the more verbose Utf8Chars::new(slice).

use utf8_iter::Utf8CharsEx;
let data = b"\xFF\xC2\xE2\xE2\x98\xF0\xF0\x9F\xF0\x9F\x92\xE2\x98\x83";
let from_iter: String = data.chars().collect();
let from_std = String::from_utf8_lossy(data);
assert_eq!(from_iter, from_std);

Modulesยง

basic ๐Ÿ”’
handler ๐Ÿ”’
UTF-8 decoding with pluggable handler for the four byte sequence lengths and error.
indices ๐Ÿ”’
macros ๐Ÿ”’
report ๐Ÿ”’
str ๐Ÿ”’

Structsยง

CharIndicesWithHandler
An iterator over the chars and their positions.
CharsWithHandler
Iterator over guaranteed-well-formed UTF-8 with Utf8Handler. The Utf8Handler::error() is, of course, never called.
DefaultHandler
The basic Output = char case.
ErrorReportingUtf8CharIndices
Iterator by Result<char,Utf8CharsError> and their indices over &[u8] that contains potentially-invalid UTF-8. See the crate documentation.
ErrorReportingUtf8Chars
Iterator by Result<char,Utf8CharsError> over &[u8] that contains potentially-invalid UTF-8. There is exactly one Utf8CharsError per each error as defined by the WHATWG Encoding Standard.
Utf8CharIndices
Iterator by char and their indices over &[u8] that contains potentially-invalid UTF-8. See the crate documentation.
Utf8CharIndicesWithHandler
An iterator over the chars and their positions.
Utf8Chars
Iterator by char over &[u8] that contains potentially-invalid UTF-8. See the crate documentation.
Utf8CharsError
A type for signaling UTF-8 errors.
Utf8CharsWithHandler
Iterator by char over &[u8] that contains potentially-invalid UTF-8 with a handler for the four kinds of byte sequences (or error). See the crate documentation.

Traitsยง

Utf8CharsEx
Convenience trait that adds chars() and char_indices() methods similar to the ones on string slices to byte slices.
Utf8Handler
Mapping from the four kinds of byte sequences or error to output.