use std::cmp::Ordering;
pub fn utf8(a: &str, b: &str) -> Ordering {
a.as_bytes().cmp(b.as_bytes())
}
pub fn utf16(a: &str, b: &str) -> Ordering {
let common = a.bytes().zip(b.bytes()).take_while(|(x, y)| x == y).count();
let start = (0..=common)
.rev()
.find(|&i| a.is_char_boundary(i))
.unwrap_or(0);
a[start..].encode_utf16().cmp(b[start..].encode_utf16())
}
#[cfg(test)]
mod tests {
use std::cmp::Ordering::*;
#[test]
fn utf16_puts_supplementary_planes_before_the_end_of_the_bmp() {
assert_eq!(super::utf16("\u{ffff}", "\u{10000}"), Greater);
assert_eq!(super::utf8("\u{ffff}", "\u{10000}"), Less);
assert_eq!(super::utf16("ab\u{e000}", "ab\u{1f600}x"), Greater);
assert_eq!(super::utf16("ab", "abc"), Less);
}
}