#[inline]
pub fn fix_arabic_chars(text: &str) -> String {
text.chars().map(canonical).collect()
}
#[inline]
fn canonical(c: char) -> char {
match c {
'ك' => 'ک', 'ي' => 'ی', 'ى' => 'ی', 'ة' => 'ه', 'إ' => 'ا', 'أ' => 'ا', '\u{FE8D}' | '\u{FE8E}' => 'ا',
'\u{FEFB}' | '\u{FEFC}' => 'ل', _ => c,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn replaces_arabic_kaf() {
assert_eq!(fix_arabic_chars("كتاب"), "کتاب");
}
#[test]
fn replaces_arabic_yeh() {
assert_eq!(fix_arabic_chars("يك"), "یک");
}
#[test]
fn replaces_teh_marbuta() {
assert_eq!(fix_arabic_chars("مدرسة"), "مدرسه");
}
#[test]
fn keeps_persian_chars_intact() {
let s = "سلام خوبی؟";
assert_eq!(fix_arabic_chars(s), s);
}
}