use crate::text::bidi::types::{BidiClass, ResolvedDirection};
pub fn detect_direction(text: &str) -> ResolvedDirection {
for c in text.chars() {
let class = BidiClass::of(c);
if class == BidiClass::L {
return ResolvedDirection::Ltr;
}
if class.is_strong_rtl() {
return ResolvedDirection::Rtl;
}
}
ResolvedDirection::Ltr
}
pub fn is_rtl_char(c: char) -> bool {
BidiClass::of(c).is_strong_rtl()
}
pub fn contains_rtl(text: &str) -> bool {
text.chars().any(is_rtl_char)
}
pub fn mirror_char(c: char) -> char {
match c {
'(' => ')',
')' => '(',
'[' => ']',
']' => '[',
'{' => '}',
'}' => '{',
'<' => '>',
'>' => '<',
'"' => '"',
'\'' => '\'',
'«' => '»',
'»' => '«',
'‹' => '›',
'›' => '‹',
'⟨' => '⟩',
'⟩' => '⟨',
'⟪' => '⟫',
'⟫' => '⟪',
'⁅' => '⁆',
'⁆' => '⁅',
_ => c,
}
}
pub fn reverse_graphemes(text: &str) -> String {
text.chars().rev().collect()
}