Function cesu8::is_valid[][src]

pub fn is_valid(str: &str) -> bool

Returns true if a string slice contains UTF-8 data that is also valid CESU-8. This is mainly used in testing if a string slice needs to be explicitly encoded using cesu8::encode().

If is_valid() returns false, it implies that &str.as_bytes() is directly equivalent to the string slice’s CESU-8 representation.

let str = "Hello, world!";
if cesu8::is_valid(&str) {
    println!("str contains valid CESU-8 data")
} else {
    panic!("str does not contain valid CESU-8 data")
}

// Any code point above U+10400 encoded in UTF-8 is not valid CESU-8.
assert!(!cesu8::is_valid("\u{10401}"));