pub(crate) mod block;
pub(crate) mod character_class;
pub(crate) mod general_category;
pub(crate) mod line_break;
pub(crate) mod lower_case;
pub(crate) mod script;
pub(crate) mod word_break;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum WordBreak {
Other,
ALetter,
Format,
Numeric,
Extend,
Katakana,
MidLetter,
MidNum,
MidNumLet,
ExtendNumLet,
SingleQuote,
DoubleQuote,
HebrewLetter,
RegionalIndicator,
CarriageReturn,
LineFeed,
Newline,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum Script {
Other,
Han,
Hiragana,
Hangul,
}
fn lookup<Value: Copy>(table: &[(u32, u32, Value)], point: u32, default: Value) -> Value {
let found = table.binary_search_by(|(first, last, _)| {
if point < *first {
std::cmp::Ordering::Greater
} else if point > *last {
std::cmp::Ordering::Less
} else {
std::cmp::Ordering::Equal
}
});
found.map_or(default, |at| table[at].2)
}
pub(crate) fn word_break(point: u32) -> WordBreak {
lookup(word_break::TABLE, point, WordBreak::Other)
}
pub(crate) fn script(point: u32) -> Script {
lookup(script::TABLE, point, Script::Other)
}
pub(crate) fn is_complex_context(point: u32) -> bool {
lookup(line_break::TABLE, point, false)
}
pub(crate) fn is_half_and_full_forms(point: u32) -> bool {
lookup(block::TABLE, point, false)
}
pub(crate) fn is_decimal_digit(point: u32) -> bool {
lookup(general_category::TABLE, point, false)
}
pub(crate) fn to_lower_case(point: u32) -> u32 {
lower_case::TABLE
.binary_search_by_key(&point, |(from, _)| *from)
.map_or(point, |at| lower_case::TABLE[at].1)
}
pub(crate) fn character_class(point: u32) -> u8 {
lookup(character_class::TABLE, point, 8)
}