todo:rename_data

This commit is contained in:
weisd
2024-07-03 17:47:28 +08:00
parent 3c70c3c6e8
commit 38b62d9d6c
6 changed files with 144 additions and 22 deletions
+16 -12
View File
@@ -1,5 +1,6 @@
const GLOBAL_DIR_SUFFIX: &str = "__XLDIR__";
const SLASH_SEPARATOR: char = '/';
const SLASH_SEPARATOR: &str = "/";
pub fn has_suffix(s: &str, suffix: &str) -> bool {
if cfg!(target_os = "windows") {
@@ -10,12 +11,8 @@ pub fn has_suffix(s: &str, suffix: &str) -> bool {
}
pub fn encode_dir_object(object: &str) -> String {
if has_suffix(object, &SLASH_SEPARATOR.to_string()) {
format!(
"{}{}",
object.trim_end_matches(SLASH_SEPARATOR),
GLOBAL_DIR_SUFFIX
)
if has_suffix(object, SLASH_SEPARATOR) {
format!("{}{}", object.trim_end_matches(SLASH_SEPARATOR), GLOBAL_DIR_SUFFIX)
} else {
object.to_string()
}
@@ -23,12 +20,19 @@ pub fn encode_dir_object(object: &str) -> String {
pub fn decode_dir_object(object: &str) -> String {
if has_suffix(object, GLOBAL_DIR_SUFFIX) {
format!(
"{}{}",
object.trim_end_matches(GLOBAL_DIR_SUFFIX),
SLASH_SEPARATOR
)
format!("{}{}", object.trim_end_matches(GLOBAL_DIR_SUFFIX), SLASH_SEPARATOR)
} else {
object.to_string()
}
}
pub fn retain_slash(s: &str) -> String {
if s.is_empty() {
return s.to_string();
}
if s.ends_with(SLASH_SEPARATOR) {
s.to_string()
} else {
format!("{}{}", s, SLASH_SEPARATOR)
}
}