whatlang/
utils.rs

1// Is it space, punctuation or digit?
2// Stop character is a character that does not give any value for script
3// or language detection.
4#[inline]
5pub fn is_stop_char(ch: char) -> bool {
6    matches!(ch, '\u{0000}'..='\u{0040}' | '\u{005B}'..='\u{0060}' | '\u{007B}'..='\u{007E}')
7}
8
9#[cfg(test)]
10mod tests {
11    use super::*;
12
13    #[test]
14    fn test_is_top_char() {
15        // stop chars
16        assert!(is_stop_char(' '));
17        assert!(is_stop_char(','));
18        assert!(is_stop_char('-'));
19        assert!(is_stop_char('-'));
20        assert!(is_stop_char('9'));
21        assert!(is_stop_char('0'));
22
23        // non-stop chars
24        assert!(!is_stop_char('a'));
25        assert!(!is_stop_char('z'));
26        assert!(!is_stop_char('A')); // latin A
27        assert!(!is_stop_char('Z'));
28        assert!(!is_stop_char('я'));
29        assert!(!is_stop_char('А')); // cyrillic A
30    }
31}