Function cesu8::is_valid_cesu8[][src]

pub fn is_valid_cesu8(str: &str) -> bool
Expand description

Returns true if a string slice contains UTF-8 data that is also valid CESU-8.

This is primarily used in testing if a string slice needs to be explicitly encoded using to_cesu8. If is_valid_cesu8() returns false, it implies that &str.as_bytes() is directly equivalent to the string slice’s CESU-8 representation.

Examples

Basic usage:

use cesu8::is_valid_cesu8;

// Any code point below or equal to U+FFFF encoded in UTF-8 IS valid CESU-8.
assert!(is_valid_cesu8("Hello, world!"));
assert!(is_valid_cesu8("\u{FFFF}"));

// Any code point above U+FFFF encoded in UTF-8 IS NOT valid CESU-8.
assert!(!is_valid_cesu8("\u{10000}"));