use crate::Char;
#[rustfmt::skip]
impl Char<u16> {
pub(crate) const CONT_MASK: u16 = 0b0011_1111;
#[must_use] #[inline(always)]
pub const fn is_surrogate(self) -> bool { matches!(self.0, 0xD800..=0xDFFF) }
#[must_use] #[inline(always)]
pub const fn is_surrogate_high(self) -> bool { matches!(self.0, 0xD800..=0xDBFF) }
#[must_use] #[inline(always)]
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(any(feature = "safe_text", not(feature = "unsafe_str")))]
return char::from_u32(code);
#[cfg(all(not(feature = "safe_text"), feature = "unsafe_str"))]
Some(unsafe { char::from_u32_unchecked(code) })
} else {
None
}
}
}