Mercurial > public > mercurial-scm > hg
comparison rust/hg-core/src/utils/hg_path.rs @ 44267:0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
In a future patch, this structure will be needed to store information needed by
the (also upcoming) `IgnoreMatcher`.
Differential Revision: https://phab.mercurial-scm.org/D7869
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Tue, 14 Jan 2020 17:04:32 +0100 |
parents | 9ab4830e9e3d |
children | 26114bd6ec60 |
comparison
equal
deleted
inserted
replaced
44266:9ab4830e9e3d | 44267:0e9ac3968b56 |
---|---|
181 &self.inner[..self.inner.len() - 1] | 181 &self.inner[..self.inner.len() - 1] |
182 } else { | 182 } else { |
183 &self.inner[..] | 183 &self.inner[..] |
184 }) | 184 }) |
185 } | 185 } |
186 /// Returns a tuple of slices `(base, filename)` resulting from the split | |
187 /// at the rightmost `/`, if any. | |
188 /// | |
189 /// # Examples: | |
190 /// | |
191 /// ``` | |
192 /// use hg::utils::hg_path::HgPath; | |
193 /// | |
194 /// let path = HgPath::new(b"cool/hg/path").split_filename(); | |
195 /// assert_eq!(path, (HgPath::new(b"cool/hg"), HgPath::new(b"path"))); | |
196 /// | |
197 /// let path = HgPath::new(b"pathwithoutsep").split_filename(); | |
198 /// assert_eq!(path, (HgPath::new(b""), HgPath::new(b"pathwithoutsep"))); | |
199 /// ``` | |
200 pub fn split_filename(&self) -> (&Self, &Self) { | |
201 match &self.inner.iter().rposition(|c| *c == b'/') { | |
202 None => (HgPath::new(""), &self), | |
203 Some(size) => ( | |
204 HgPath::new(&self.inner[..*size]), | |
205 HgPath::new(&self.inner[*size + 1..]), | |
206 ), | |
207 } | |
208 } | |
186 pub fn join<T: ?Sized + AsRef<Self>>(&self, other: &T) -> HgPathBuf { | 209 pub fn join<T: ?Sized + AsRef<Self>>(&self, other: &T) -> HgPathBuf { |
187 let mut inner = self.inner.to_owned(); | 210 let mut inner = self.inner.to_owned(); |
188 if inner.len() != 0 && inner.last() != Some(&b'/') { | 211 if inner.len() != 0 && inner.last() != Some(&b'/') { |
189 inner.push(b'/'); | 212 inner.push(b'/'); |
190 } | 213 } |