Mercurial > public > mercurial-scm > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
46668:fb2368598281 | 46669:e8cd519a0a34 |
---|---|
65 } | 65 } |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 pub trait SliceExt { | 69 pub trait SliceExt { |
70 fn trim_end_newlines(&self) -> &Self; | |
70 fn trim_end(&self) -> &Self; | 71 fn trim_end(&self) -> &Self; |
71 fn trim_start(&self) -> &Self; | 72 fn trim_start(&self) -> &Self; |
72 fn trim(&self) -> &Self; | 73 fn trim(&self) -> &Self; |
73 fn drop_prefix(&self, needle: &Self) -> Option<&Self>; | 74 fn drop_prefix(&self, needle: &Self) -> Option<&Self>; |
74 fn split_2(&self, separator: u8) -> Option<(&[u8], &[u8])>; | 75 fn split_2(&self, separator: u8) -> Option<(&[u8], &[u8])>; |
78 fn is_not_whitespace(c: &u8) -> bool { | 79 fn is_not_whitespace(c: &u8) -> bool { |
79 !(*c as char).is_whitespace() | 80 !(*c as char).is_whitespace() |
80 } | 81 } |
81 | 82 |
82 impl SliceExt for [u8] { | 83 impl SliceExt for [u8] { |
84 fn trim_end_newlines(&self) -> &[u8] { | |
85 if let Some(last) = self.iter().rposition(|&byte| byte != b'\n') { | |
86 &self[..=last] | |
87 } else { | |
88 &[] | |
89 } | |
90 } | |
83 fn trim_end(&self) -> &[u8] { | 91 fn trim_end(&self) -> &[u8] { |
84 if let Some(last) = self.iter().rposition(is_not_whitespace) { | 92 if let Some(last) = self.iter().rposition(is_not_whitespace) { |
85 &self[..=last] | 93 &self[..=last] |
86 } else { | 94 } else { |
87 &[] | 95 &[] |