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
use std::cmp::Ordering;
use std::borrow::Cow;
pub struct GlobalStatePathHelper;
impl GlobalStatePathHelper {
pub fn fix_path<'a>(path: &'a str) -> Cow<'a, str> {
let path = path.trim();
let ret = match path.ends_with("/") {
true => {
if path.starts_with('/') {
Cow::Borrowed(path)
} else {
Cow::Owned(format!("/{}", path))
}
}
false => {
if path.starts_with('/') {
Cow::Owned(format!("{}/", path))
} else {
Cow::Owned(format!("/{}/", path))
}
}
};
ret
}
pub fn compare_path(left: &String, right: &String) -> Option<Ordering> {
let len1 = left.len();
let len2 = right.len();
if len1 > len2 {
Some(Ordering::Less)
} else if len1 < len2 {
Some(Ordering::Greater)
} else {
left.partial_cmp(right)
}
}
}