use super::VowelClassifier;
#[derive(Debug, Clone, Copy, Default)]
pub struct GurmukhiClassifier;
impl GurmukhiClassifier {
pub fn new() -> Self {
Self
}
}
static GURMUKHI_VOWELS: &[char] = &[
'ਅ', 'ਆ', 'ਇ', 'ਈ', 'ਉ', 'ਊ', 'ਏ', 'ਐ', 'ਓ', 'ਔ', 'ਾ', 'ਿ', 'ੀ', 'ੁ', 'ੂ', 'ੇ', 'ੈ', 'ੋ', 'ੌ', ];
impl VowelClassifier for GurmukhiClassifier {
fn is_vowel(&self, c: char) -> bool {
let code = c as u32;
match code {
0x0A05..=0x0A0A => true, 0x0A0F..=0x0A10 => true, 0x0A13..=0x0A14 => true,
0x0A3E..=0x0A42 => true, 0x0A47..=0x0A48 => true, 0x0A4B..=0x0A4C => true,
_ => false,
}
}
fn script_name(&self) -> &'static str {
"Gurmukhi"
}
fn vowels(&self) -> &[char] {
GURMUKHI_VOWELS
}
fn is_consonant(&self, c: char) -> bool {
let code = c as u32;
match code {
0x0A15..=0x0A28 => true, 0x0A2A..=0x0A30 => true, 0x0A32..=0x0A33 => true, 0x0A35..=0x0A36 => true, 0x0A38..=0x0A39 => true,
0x0A59..=0x0A5C => true, 0x0A5E => true,
0x0A4D => false,
0x0A01..=0x0A03 => false,
_ => false,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_independent_vowels() {
let c = GurmukhiClassifier::new();
assert!(c.is_vowel('ਅ')); assert!(c.is_vowel('ਆ')); assert!(c.is_vowel('ਇ')); assert!(c.is_vowel('ਈ')); assert!(c.is_vowel('ਉ')); assert!(c.is_vowel('ਊ')); assert!(c.is_vowel('ਏ')); assert!(c.is_vowel('ਐ')); assert!(c.is_vowel('ਓ')); assert!(c.is_vowel('ਔ')); }
#[test]
fn test_dependent_vowels() {
let c = GurmukhiClassifier::new();
assert!(c.is_vowel('ਾ')); assert!(c.is_vowel('ਿ')); assert!(c.is_vowel('ੀ')); assert!(c.is_vowel('ੁ')); assert!(c.is_vowel('ੂ')); assert!(c.is_vowel('ੇ')); assert!(c.is_vowel('ੈ')); }
#[test]
fn test_consonants() {
let c = GurmukhiClassifier::new();
assert!(!c.is_vowel('ਕ')); assert!(!c.is_vowel('ਖ')); assert!(!c.is_vowel('ਗ')); assert!(!c.is_vowel('ਘ')); assert!(!c.is_vowel('ਚ')); assert!(!c.is_vowel('ਜ')); assert!(!c.is_vowel('ਤ')); assert!(!c.is_vowel('ਦ')); assert!(!c.is_vowel('ਨ')); assert!(!c.is_vowel('ਪ')); assert!(!c.is_vowel('ਮ')); assert!(!c.is_vowel('ਹ')); }
#[test]
fn test_nukta_consonants() {
let c = GurmukhiClassifier::new();
assert!(!c.is_vowel('\u{0A16}')); assert!(!c.is_vowel('\u{0A17}')); assert!(!c.is_vowel('\u{0A1C}')); assert!(!c.is_vowel('\u{0A5C}')); assert!(!c.is_vowel('\u{0A2B}')); assert!(!c.is_consonant('\u{0A3C}')); }
#[test]
fn test_is_consonant() {
let c = GurmukhiClassifier::new();
assert!(c.is_consonant('ਕ')); assert!(c.is_consonant('ਗ')); assert!(c.is_consonant('ਤ')); assert!(c.is_consonant('ਨ')); assert!(c.is_consonant('ਮ')); assert!(c.is_consonant('ਹ')); }
#[test]
fn test_virama_not_vowel() {
let c = GurmukhiClassifier::new();
assert!(!c.is_vowel('੍')); assert!(!c.is_consonant('੍')); }
#[test]
fn test_diacritics() {
let c = GurmukhiClassifier::new();
assert!(!c.is_vowel('ਁ')); assert!(!c.is_vowel('ਂ')); assert!(!c.is_vowel('ਃ')); assert!(!c.is_consonant('ਁ'));
assert!(!c.is_consonant('ਂ'));
assert!(!c.is_consonant('ਃ'));
}
}