equal
deleted
inserted
replaced
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 } |