use icu_properties::{CodePointMapDataBorrowed, props::JoiningType};
use crate::prelude::*;
static JT: CodePointMapDataBorrowed<JoiningType> = CodePointMapDataBorrowed::new();
const JTT: JoiningType = JoiningType::Transparent;
const JTL: JoiningType = JoiningType::LeftJoining;
const JTR: JoiningType = JoiningType::RightJoining;
const JTD: JoiningType = JoiningType::DualJoining;
fn jtt (c: char) -> bool {matches!(JT.get(c), JTT)}
fn jtld(c: char) -> bool {matches!(JT.get(c), JTL | JTD)}
fn jtrd(c: char) -> bool {matches!(JT.get(c), JTR | JTD)}
fn cccv(c: char) -> bool {UTS46.is_virama(c)}
pub fn validate_domain_segment_joiners(value: &str) -> bool {
if value.memchr(b'\xE2').is_some() {
let mut x = value.split('\u{200C}').peekable();
while let Some((l, &r)) = x.next().zip(x.peek()) {
if !(l.ends_with(cccv) || (l.trim_end_matches(jtt).ends_with(jtld) && r.trim_start_matches(jtt).starts_with(jtrd))) {
return false;
}
}
let mut x = value.split('\u{200D}').peekable();
while let Some((l, _)) = x.next().zip(x.peek()) {
if !l.ends_with(cccv) {
return false;
}
}
}
true
}