1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/// Checks if the string contains only alphabetic characters.
///
/// # Arguments
///
/// * `s` - The string to check.
///
/// # Returns
///
/// Returns true if string contains only alphabetic characters, false if not.
///
/// # Examples
///
/// ```
/// use rufl::string;
///
/// assert_eq!(true, string::is_alpha("abc"));
///
/// assert_eq!(true, string::is_alpha("żółć"));
///
/// assert_eq!(true, string::is_alpha("你好"));
///
/// assert_eq!(false, string::is_alpha("a̐éö̲"));
///
/// ```
pub fn is_alpha(s: &str) -> bool {
return s.chars().all(|c| c.is_alphabetic());
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_is_alpha() {
assert_eq!(true, is_alpha("foo"));
assert_eq!(true, is_alpha("żółć"));
assert_eq!(true, is_alpha("你好"));
assert_eq!(true, is_alpha(""));
assert_eq!(false, is_alpha("a̐éö̲"));
assert_eq!(false, is_alpha("café"));
assert_eq!(false, is_alpha("foo1"));
}
}