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
48
49
50
51
52
/// Returns the substring after the first occurrence of a specified `substr` in the source string.
///
/// # Arguments
///
/// * `s` - The input string to perform after operation.
/// * `substr` - The substring to look for first occurrence in `s`.
///
/// # Returns
///
/// Returns the substring after the first occurrence of `substr` in `s`.
///
/// # Examples
///
/// ```
/// use rufl::string;
///
/// let foo = string::after("foo", "f");
/// assert_eq!("oo", foo);
///
/// let bar = string::after("bar", "a");
/// assert_eq!("r", bar);
///
/// let boo = string::after("boo", "c");
/// assert_eq!("boo", boo);
///
/// ```
pub fn after(s: impl AsRef<str>, substr: &str) -> String {
match s.as_ref().find(substr) {
Some(index) => s.as_ref()[index + substr.len()..].to_string(),
None => s.as_ref().to_string(),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_after() {
assert_eq!("foo", after("foo", ""));
assert_eq!("foo", after("foo", "a"));
assert_eq!("", after("foo", "foo"));
assert_eq!("bar/boo", after("foo/bar/boo", "/"));
assert_eq!("你好你好", after("你好你好你好", "你好"));
assert_eq!(
" programátor",
after("Jsem počítačový programátor", "počítačový")
);
}
}