cyfs_lib/rmeta/def/
path.rs

1
2use std::cmp::Ordering;
3use std::borrow::Cow;
4
5pub struct GlobalStatePathHelper;
6
7impl GlobalStatePathHelper {
8    pub fn fix_path<'a>(path: &'a str) -> Cow<'a, str> {
9        let path = path.trim();
10
11        let ret = match path.ends_with("/") {
12            true => {
13                if path.starts_with('/') {
14                    Cow::Borrowed(path)
15                } else {
16                    Cow::Owned(format!("/{}", path))
17                }
18            }
19            false => {
20                if path.starts_with('/') {
21                    Cow::Owned(format!("{}/", path))
22                } else {
23                    Cow::Owned(format!("/{}/", path))
24                }
25            }
26        };
27
28        ret
29    }
30
31    pub fn compare_path(left: &String, right: &String) -> Option<Ordering> {
32        let len1 = left.len();
33        let len2 = right.len();
34
35        if len1 > len2 {
36            Some(Ordering::Less)
37        } else if len1 < len2 {
38            Some(Ordering::Greater)
39        } else {
40            left.partial_cmp(right)
41        }
42    }
43}