mod unicode_17;
use icu_properties::{
props::{CaseIgnorable, Cased, WhiteSpace},
CodePointSetData, CodePointSetDataBorrowed,
};
pub(crate) const VERSION: (u8, u8, u8) = (16, 0, 0);
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub(crate) enum Profile {
#[default]
Unicode16,
Unicode17,
}
impl Profile {
pub(crate) fn from_version(version: Option<(u8, u8, u8)>) -> crate::AnalysisResult<Self> {
match version {
None | Some((16, 0, 0)) => Ok(Self::Unicode16),
Some((17, 0, 0)) => Ok(Self::Unicode17),
_ => Err(crate::AnalysisError::Descriptor(
"unsupported Unicode profile",
)),
}
}
pub(crate) fn version(self) -> (u8, u8, u8) {
match self {
Self::Unicode16 => VERSION,
Self::Unicode17 => (17, 0, 0),
}
}
pub(crate) fn lowercase_override(self, character: char) -> Option<char> {
match self {
Self::Unicode16 => None,
Self::Unicode17 => unicode_17::LOWERCASE
.binary_search_by_key(&character, |&(upper, _)| upper)
.ok()
.map(|index| unicode_17::LOWERCASE[index].1),
}
}
}
pub(crate) const CASED: CodePointSetDataBorrowed<'static> = CodePointSetData::new::<Cased>();
pub(crate) const CASE_IGNORABLE: CodePointSetDataBorrowed<'static> =
CodePointSetData::new::<CaseIgnorable>();
pub(crate) fn is_whitespace(character: char) -> bool {
CodePointSetData::new::<WhiteSpace>().contains(character)
}