use crate::Char;
#[rustfmt::skip]
impl Char<u16> {
#[must_use]
pub const fn is_surrogate(self) -> bool { matches!(self.0, 0xD800..=0xDFFF) }
#[must_use]
pub const fn is_surrogate_high(self) -> bool { matches!(self.0, 0xD800..=0xDBFF) }
#[must_use]
pub const fn is_surrogate_low(self) -> bool { matches!(self.0, 0xDC00..=0xDFFF) }
#[must_use]
pub const fn decode_surrogate_pair(high: u16, low: u16) -> Option<char> {
if Char(high).is_surrogate_high() && Char(low).is_surrogate_low() {
let code = 0x10000 + (((high as u32 - 0xD800) << 10) | (low as u32 - 0xDC00));
cfg_select! { all(feature = "unsafe_str", not(feature = "safe_text")) => {
Some(unsafe { char::from_u32_unchecked(code) }) } _ => { char::from_u32(code) }}
} else {
None
}
}
}