From f3b7620259682a5afc511556209e1fdd45c238de Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Tue, 24 Feb 2026 18:35:03 +0800 Subject: Move sheet file R/W to v1 module --- systems/sheet/src/mapping.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'systems/sheet/src/mapping.rs') 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> 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) -> Vec { + let str = just_fmt::fmt_path::fmt_path_str(str).unwrap_or_default(); + str.split("/").into_iter().map(|f| f.to_string()).collect() +} -- cgit