Mercurial > public > mercurial-scm > hg
diff rust/hg-core/src/utils.rs @ 46669:e8cd519a0a34
rhg: Ignore trailing newlines in .hg/sharedpath
Differential Revision: https://phab.mercurial-scm.org/D10132
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Thu, 04 Mar 2021 13:26:53 +0100 |
parents | a069639783a0 |
children | 91ab5190a3de |
line wrap: on
line diff
--- a/rust/hg-core/src/utils.rs Tue Mar 02 21:31:12 2021 +0100 +++ b/rust/hg-core/src/utils.rs Thu Mar 04 13:26:53 2021 +0100 @@ -67,6 +67,7 @@ } pub trait SliceExt { + fn trim_end_newlines(&self) -> &Self; fn trim_end(&self) -> &Self; fn trim_start(&self) -> &Self; fn trim(&self) -> &Self; @@ -80,6 +81,13 @@ } impl SliceExt for [u8] { + fn trim_end_newlines(&self) -> &[u8] { + if let Some(last) = self.iter().rposition(|&byte| byte != b'\n') { + &self[..=last] + } else { + &[] + } + } fn trim_end(&self) -> &[u8] { if let Some(last) = self.iter().rposition(is_not_whitespace) { &self[..=last]