use crate::unicode::props::*;
use crate::unicode::CodePoint;
use crate::unicode::Ucd;
use crate::unicode::Incb;
pub(crate) fn math(cp: u32) -> bool {
let cp = CodePoint::new(cp).unwrap();
if cp.gc() == Gc::Sm || cp.omath() {
return true;
}
false
}
pub(crate) fn alpha(cp: u32) -> bool {
let cp = CodePoint::new(cp).unwrap();
let gc = cp.gc();
cp.upper()
|| cp.lower()
|| gc == Gc::Lt
|| gc == Gc::Lm
|| gc == Gc::Lo
|| gc == Gc::Nl
|| cp.oalpha()
}
pub(crate) fn lower(cp: u32) -> bool {
let cp = CodePoint::new(cp).unwrap();
cp.gc() == Gc::Ll || cp.olower()
}
pub(crate) fn upper(cp: u32) -> bool {
let cp = CodePoint::new(cp).unwrap();
cp.gc() == Gc::Lu || cp.oupper()
}
pub(crate) fn cased(cp: u32) -> bool {
let cp = CodePoint::new(cp).unwrap();
cp.lower() || cp.upper() || cp.gc() == Gc::Lt
}
pub(crate) fn ci(cp: u32) -> bool {
let cp = CodePoint::new(cp).unwrap();
let wb = cp.wb();
let gc = cp.gc();
wb == Wb::ML || wb == Wb::MB || wb == Wb::SQ ||
gc == Gc::Mn || gc == Gc::Me || gc == Gc::Cf || gc == Gc::Lm || gc == Gc::Sk
}
pub(crate) fn ids(cp: u32) -> bool {
let cp = CodePoint::new(cp).unwrap();
let gc = cp.gc();
if (gc == Gc::Lu || gc == Gc::Ll || gc == Gc::Lt || gc == Gc::Lm ||
gc == Gc::Lo || gc == Gc::Nl ||
cp.oids()) &&
(!cp.pat_syn()) &&
(!cp.pat_ws()) {
return true;
}
false
}
pub(crate) fn idc(cp: u32) -> bool {
let cp = CodePoint::new(cp).unwrap();
let gc = cp.gc();
if (cp.ids() || gc == Gc::Mn || gc == Gc::Mc || gc == Gc::Nd || gc == Gc::Pc ||
cp.oidc()) &&
!cp.pat_syn() &&
!cp.pat_ws() {
return true;
}
false
}
pub(crate) fn xids(cp: u32) -> bool {
let excludes: &[u32] = &[0x0E33, 0x0EB3, 0xFF9E, 0xFF9F, 0x037A, 0x309B,
0x309C, 0xFDFA, 0xFDFB, 0xFE70, 0xFE72, 0xFE74,
0xFE76, 0xFE78, 0xFE7A, 0xFE7C, 0xFE7E, 0xFF9E,
0xFF9F,
];
ids(cp) && !excludes.contains(&cp) && !(0xFC5E..=0xFC63).contains(&cp)
}
pub(crate) fn xidc(cp: u32) -> bool {
let excludes: &[u32] = &[0x037A, 0x309B,
0x309C, 0xFDFA, 0xFDFB, 0xFE70, 0xFE72, 0xFE74,
0xFE76, 0xFE78, 0xFE7A, 0xFE7C, 0xFE7E,
];
idc(cp) && !excludes.contains(&cp) && !(0xFC5E..=0xFC63).contains(&cp)
}
pub(crate) fn di(cp: u32) -> bool {
let cp = CodePoint::new(cp).unwrap();
if cp.odi() || cp.gc() == Gc::Cf || cp.vs() {
if !cp.wspace() && !(0xFFF9..=0xFFFB).contains(&cp.to_u32()) &&
!(0x13430..=0x13440).contains(&cp.to_u32()) &&
!cp.pcm() {
return true;
}
}
return false;
}
pub(crate) fn gr_ext(cp: u32) -> bool {
let cp = CodePoint::new(cp).unwrap();
cp.gc() == Gc::Me || cp.gc() == Gc::Mn || cp.ogr_ext()
}
fn is_incb_linker(cp: u32) -> bool {
let set = [Sc::Beng, Sc::Deva, Sc::Gujr, Sc::Mlym, Sc::Orya, Sc::Telu];
let cp = CodePoint::new(cp).unwrap();
let sc = cp.sc();
if set.contains(&sc) && cp.insc() == Insc::Virama {
return true;
}
false
}
fn is_incb_consonant(cp: u32) -> bool {
let set = [Sc::Beng, Sc::Deva, Sc::Gujr, Sc::Mlym, Sc::Orya, Sc::Telu];
let cp = CodePoint::new(cp).unwrap();
let sc = cp.sc();
if set.contains(&sc) && cp.insc() == Insc::Consonant {
return true;
};
false
}
pub(crate) fn incb(cp: u32) -> Incb {
if is_incb_linker(cp) {
return Incb::Linker;
}
if is_incb_consonant(cp) {
return Incb::Consonant;
}
let code_point = CodePoint::new(cp).unwrap();
let gcb = code_point.gcb();
if gcb == Gcb::EX || gcb == Gcb::ZWJ {
if !is_incb_linker(cp) && !is_incb_consonant(cp) && cp != 0x200C {
return Incb::Extend;
}
return Incb::None;
}
Incb::None
}