summaryrefslogtreecommitdiff
path: root/systems/sheet/src/mapping.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-02-24 18:35:03 +0800
committer魏曹先生 <1992414357@qq.com>2026-02-24 18:35:03 +0800
commitf3b7620259682a5afc511556209e1fdd45c238de (patch)
tree19aa242fa5ebf649290fd4af41ad181dd779d961 /systems/sheet/src/mapping.rs
parent00aa123a7cd74ee0307157fdbb31679c01f1db33 (diff)
Move sheet file R/W to v1 module
Diffstat (limited to 'systems/sheet/src/mapping.rs')
-rw-r--r--systems/sheet/src/mapping.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/systems/sheet/src/mapping.rs b/systems/sheet/src/mapping.rs
index 0a72a69..1743534 100644
--- a/systems/sheet/src/mapping.rs
+++ b/systems/sheet/src/mapping.rs
@@ -507,6 +507,11 @@ impl LocalMapping {
pub fn set_forward(&mut self, forward: &LocalMappingForward) {
self.forward = forward.clone();
}
+
+ /// Replace the forward direction of the current LocalMapping
+ pub fn replace_forward(&mut self, forward: LocalMappingForward) {
+ self.forward = forward;
+ }
}
#[inline(always)]
@@ -591,3 +596,31 @@ impl std::borrow::Borrow<Vec<String>> for MappingBuf {
&self.val
}
}
+
+/// Convert a string into a Node suitable for Mapping
+///
+/// # Examples
+///
+/// ```
+/// # use sheet_system::mapping::node;
+/// assert_eq!(
+/// node("./home/path1/"),
+/// vec!["home".to_string(), "path1".to_string(), "".to_string()]
+/// );
+/// assert_eq!(
+/// node("./home/path2"),
+/// vec!["home".to_string(), "path2".to_string()]
+/// );
+/// assert_eq!(
+/// node(".\\home\\path3\\"),
+/// vec!["home".to_string(), "path3".to_string(), "".to_string()]
+/// );
+/// assert_eq!(
+/// node("home/path4"),
+/// vec!["home".to_string(), "path4".to_string()]
+/// );
+/// ```
+pub fn node(str: impl Into<String>) -> Vec<String> {
+ let str = just_fmt::fmt_path::fmt_path_str(str).unwrap_or_default();
+ str.split("/").into_iter().map(|f| f.to_string()).collect()
+}