#![no_std]
use icu_normalizer::properties::CanonicalCombiningClassMap;
use icu_normalizer::uts46::Uts46Mapper;
use icu_properties::maps::CodePointMapDataBorrowed;
use icu_properties::CanonicalCombiningClass;
use icu_properties::GeneralCategory;
const fn joining_type_to_mask(jt: icu_properties::JoiningType) -> u32 {
1u32 << jt.0
}
pub const LEFT_OR_DUAL_JOINING_MASK: JoiningTypeMask = JoiningTypeMask(
joining_type_to_mask(icu_properties::JoiningType::LeftJoining)
| joining_type_to_mask(icu_properties::JoiningType::DualJoining),
);
pub const RIGHT_OR_DUAL_JOINING_MASK: JoiningTypeMask = JoiningTypeMask(
joining_type_to_mask(icu_properties::JoiningType::RightJoining)
| joining_type_to_mask(icu_properties::JoiningType::DualJoining),
);
const fn bidi_class_to_mask(bc: icu_properties::BidiClass) -> u32 {
1u32 << bc.0
}
pub const RTL_MASK: BidiClassMask = BidiClassMask(
bidi_class_to_mask(icu_properties::BidiClass::RightToLeft)
| bidi_class_to_mask(icu_properties::BidiClass::ArabicLetter)
| bidi_class_to_mask(icu_properties::BidiClass::ArabicNumber),
);
pub const FIRST_BC_MASK: BidiClassMask = BidiClassMask(
bidi_class_to_mask(icu_properties::BidiClass::LeftToRight)
| bidi_class_to_mask(icu_properties::BidiClass::RightToLeft)
| bidi_class_to_mask(icu_properties::BidiClass::ArabicLetter),
);
pub const LAST_LTR_MASK: BidiClassMask = BidiClassMask(
bidi_class_to_mask(icu_properties::BidiClass::LeftToRight)
| bidi_class_to_mask(icu_properties::BidiClass::EuropeanNumber),
);
pub const LAST_RTL_MASK: BidiClassMask = BidiClassMask(
bidi_class_to_mask(icu_properties::BidiClass::RightToLeft)
| bidi_class_to_mask(icu_properties::BidiClass::ArabicLetter)
| bidi_class_to_mask(icu_properties::BidiClass::EuropeanNumber)
| bidi_class_to_mask(icu_properties::BidiClass::ArabicNumber),
);
pub const MIDDLE_LTR_MASK: BidiClassMask = BidiClassMask(
bidi_class_to_mask(icu_properties::BidiClass::LeftToRight)
| bidi_class_to_mask(icu_properties::BidiClass::EuropeanNumber)
| bidi_class_to_mask(icu_properties::BidiClass::EuropeanSeparator)
| bidi_class_to_mask(icu_properties::BidiClass::CommonSeparator)
| bidi_class_to_mask(icu_properties::BidiClass::EuropeanTerminator)
| bidi_class_to_mask(icu_properties::BidiClass::OtherNeutral)
| bidi_class_to_mask(icu_properties::BidiClass::BoundaryNeutral)
| bidi_class_to_mask(icu_properties::BidiClass::NonspacingMark),
);
pub const MIDDLE_RTL_MASK: BidiClassMask = BidiClassMask(
bidi_class_to_mask(icu_properties::BidiClass::RightToLeft)
| bidi_class_to_mask(icu_properties::BidiClass::ArabicLetter)
| bidi_class_to_mask(icu_properties::BidiClass::ArabicNumber)
| bidi_class_to_mask(icu_properties::BidiClass::EuropeanNumber)
| bidi_class_to_mask(icu_properties::BidiClass::EuropeanSeparator)
| bidi_class_to_mask(icu_properties::BidiClass::CommonSeparator)
| bidi_class_to_mask(icu_properties::BidiClass::EuropeanTerminator)
| bidi_class_to_mask(icu_properties::BidiClass::OtherNeutral)
| bidi_class_to_mask(icu_properties::BidiClass::BoundaryNeutral)
| bidi_class_to_mask(icu_properties::BidiClass::NonspacingMark),
);
const fn general_category_to_mask(gc: GeneralCategory) -> u32 {
1 << (gc as u32)
}
const MARK_MASK: u32 = general_category_to_mask(GeneralCategory::NonspacingMark)
| general_category_to_mask(GeneralCategory::SpacingMark)
| general_category_to_mask(GeneralCategory::EnclosingMark);
#[repr(transparent)]
#[derive(Clone, Copy)]
pub struct JoiningType(icu_properties::JoiningType);
impl JoiningType {
#[inline(always)]
pub fn to_mask(self) -> JoiningTypeMask {
JoiningTypeMask(joining_type_to_mask(self.0))
}
#[inline(always)]
pub fn is_transparent(self) -> bool {
self.0 == icu_properties::JoiningType::Transparent
}
}
#[repr(transparent)]
#[derive(Clone, Copy)]
pub struct JoiningTypeMask(u32);
impl JoiningTypeMask {
#[inline(always)]
pub fn intersects(self, other: JoiningTypeMask) -> bool {
self.0 & other.0 != 0
}
}
#[repr(transparent)]
#[derive(Clone, Copy)]
pub struct BidiClass(icu_properties::BidiClass);
impl BidiClass {
#[inline(always)]
pub fn to_mask(self) -> BidiClassMask {
BidiClassMask(bidi_class_to_mask(self.0))
}
#[inline(always)]
pub fn is_ltr(self) -> bool {
self.0 == icu_properties::BidiClass::LeftToRight
}
#[inline(always)]
pub fn is_nonspacing_mark(self) -> bool {
self.0 == icu_properties::BidiClass::NonspacingMark
}
#[inline(always)]
pub fn is_european_number(self) -> bool {
self.0 == icu_properties::BidiClass::EuropeanNumber
}
#[inline(always)]
pub fn is_arabic_number(self) -> bool {
self.0 == icu_properties::BidiClass::ArabicNumber
}
}
#[repr(transparent)]
#[derive(Clone, Copy)]
pub struct BidiClassMask(u32);
impl BidiClassMask {
#[inline(always)]
pub fn intersects(self, other: BidiClassMask) -> bool {
self.0 & other.0 != 0
}
}
pub struct Adapter {
mapper: Uts46Mapper,
canonical_combining_class: CanonicalCombiningClassMap,
general_category: CodePointMapDataBorrowed<'static, GeneralCategory>,
bidi_class: CodePointMapDataBorrowed<'static, icu_properties::BidiClass>,
joining_type: CodePointMapDataBorrowed<'static, icu_properties::JoiningType>,
}
#[cfg(feature = "compiled_data")]
impl Default for Adapter {
fn default() -> Self {
Self::new()
}
}
impl Adapter {
#[cfg(feature = "compiled_data")]
#[inline(always)]
pub const fn new() -> Self {
Self {
mapper: Uts46Mapper::new(),
canonical_combining_class: CanonicalCombiningClassMap::new(),
general_category: icu_properties::maps::general_category(),
bidi_class: icu_properties::maps::bidi_class(),
joining_type: icu_properties::maps::joining_type(),
}
}
#[inline(always)]
pub fn is_virama(&self, c: char) -> bool {
self.canonical_combining_class.get(c) == CanonicalCombiningClass::Virama
}
#[inline(always)]
pub fn is_mark(&self, c: char) -> bool {
(general_category_to_mask(self.general_category.get(c)) & MARK_MASK) != 0
}
#[inline(always)]
pub fn bidi_class(&self, c: char) -> BidiClass {
BidiClass(self.bidi_class.get(c))
}
#[inline(always)]
pub fn joining_type(&self, c: char) -> JoiningType {
JoiningType(self.joining_type.get(c))
}
#[inline(always)]
pub fn map_normalize<'delegate, I: Iterator<Item = char> + 'delegate>(
&'delegate self,
iter: I,
) -> impl Iterator<Item = char> + 'delegate {
self.mapper.map_normalize(iter)
}
#[inline(always)]
pub fn normalize_validate<'delegate, I: Iterator<Item = char> + 'delegate>(
&'delegate self,
iter: I,
) -> impl Iterator<Item = char> + 'delegate {
self.mapper.normalize_validate(iter)
}
}