use super::VowelClassifier;
#[derive(Debug, Clone, Copy, Default)]
pub struct LatinClassifier {
pub y_is_vowel: bool,
}
impl LatinClassifier {
pub fn new() -> Self {
Self::default()
}
pub fn with_y_as_vowel() -> Self {
Self { y_is_vowel: true }
}
}
static LATIN_VOWELS: &[char] = &[
'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U', 'á', 'é', 'í', 'ó', 'ú', 'Á', 'É', 'Í', 'Ó', 'Ú', 'à', 'è', 'ì', 'ò', 'ù', 'À', 'È', 'Ì', 'Ò', 'Ù', 'â', 'ê', 'î', 'ô', 'û', 'Â', 'Ê', 'Î', 'Ô', 'Û', 'ä', 'ë', 'ï', 'ö', 'ü', 'Ä', 'Ë', 'Ï', 'Ö', 'Ü', 'ã', 'õ', 'ñ', 'Ã', 'Õ', 'Ñ', 'æ', 'ø', 'å', 'Æ', 'Ø', 'Å', 'œ', 'Œ', ];
impl VowelClassifier for LatinClassifier {
fn is_vowel(&self, c: char) -> bool {
match c {
'a' | 'e' | 'i' | 'o' | 'u' | 'A' | 'E' | 'I' | 'O' | 'U' => true,
'y' | 'Y' if self.y_is_vowel => true,
'á' | 'é' | 'í' | 'ó' | 'ú' | 'Á' | 'É' | 'Í' | 'Ó' | 'Ú' => true,
'à' | 'è' | 'ì' | 'ò' | 'ù' | 'À' | 'È' | 'Ì' | 'Ò' | 'Ù' => true,
'â' | 'ê' | 'î' | 'ô' | 'û' | 'Â' | 'Ê' | 'Î' | 'Ô' | 'Û' => true,
'ä' | 'ë' | 'ï' | 'ö' | 'ü' | 'Ä' | 'Ë' | 'Ï' | 'Ö' | 'Ü' => true,
'ã' | 'õ' | 'Ã' | 'Õ' => true,
'æ' | 'ø' | 'å' | 'Æ' | 'Ø' | 'Å' => true,
'œ' | 'Œ' => true,
'ı' | 'İ' => true,
_ => false,
}
}
fn script_name(&self) -> &'static str {
"Latin"
}
fn vowels(&self) -> &[char] {
LATIN_VOWELS
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_basic_vowels() {
let c = LatinClassifier::new();
assert!(c.is_vowel('a'));
assert!(c.is_vowel('e'));
assert!(c.is_vowel('i'));
assert!(c.is_vowel('o'));
assert!(c.is_vowel('u'));
assert!(c.is_vowel('A'));
assert!(c.is_vowel('E'));
assert!(c.is_vowel('I'));
assert!(c.is_vowel('O'));
assert!(c.is_vowel('U'));
}
#[test]
fn test_accented_vowels() {
let c = LatinClassifier::new();
assert!(c.is_vowel('á'));
assert!(c.is_vowel('é'));
assert!(c.is_vowel('ñ') == false); assert!(c.is_vowel('ö'));
assert!(c.is_vowel('ü'));
assert!(c.is_vowel('ã'));
assert!(c.is_vowel('æ'));
}
#[test]
fn test_consonants() {
let c = LatinClassifier::new();
assert!(!c.is_vowel('b'));
assert!(!c.is_vowel('c'));
assert!(!c.is_vowel('d'));
assert!(!c.is_vowel('z'));
assert!(!c.is_vowel('ñ'));
assert!(!c.is_vowel('ß'));
}
#[test]
fn test_y_handling() {
let default = LatinClassifier::new();
assert!(!default.is_vowel('y'));
let with_y = LatinClassifier::with_y_as_vowel();
assert!(with_y.is_vowel('y'));
assert!(with_y.is_vowel('Y'));
}
#[test]
fn test_turkish_dotless_i() {
let c = LatinClassifier::new();
assert!(c.is_vowel('ı')); assert!(c.is_vowel('İ')); }
}