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
46
47
/// Split the input string into a vector of str.
///
///
/// # Arguments
///
/// * `s` - The input string to split into characters.
///
/// # Returns
///
/// Returns a vector containing the characters extracted from the input string.
///
/// # Example
///
/// ```rust
/// use rufl::string;
///
/// assert_eq!(vec!["h", "e", "l", "l", "o"], string::split_chars("hello"));
///
/// assert_eq!(vec!["你", "好"], string::split_chars("你好"));
///
/// ```
pub fn split_chars(s: &str) -> Vec<&str> {
if s.is_empty() {
return vec![""];
}
s.split_terminator("").skip(1).collect::<Vec<_>>()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_split_chars() {
assert_eq!(vec![""], split_chars(""));
assert_eq!(vec!["h", "e", "l", "l", "o"], split_chars("hello"));
assert_eq!(vec!["S", "z", "e", "ś", "ć"], split_chars("Sześć"));
assert_eq!(vec!["你", "好"], split_chars("你好"));
assert_eq!(
vec!["a", "\u{310}", "e", "\u{301}", "o", "\u{308}", "\u{332}"],
split_chars("a̐éö̲")
);
}
}