Mercurial > public > mercurial-scm > hg-stable
comparison rust/hg-core/src/utils.rs @ 42869:62eabdf91f85
rustfilepatterns: refactor the pattern of removing a prefix from a &[u8]
Differential Revision: https://phab.mercurial-scm.org/D6766
author | Valentin Gatien-Baron <valentin.gatienbaron@gmail.com> |
---|---|
date | Mon, 26 Aug 2019 08:25:01 -0400 |
parents | ce6797ef6eab |
children | 3fe40dd6355d |
comparison
equal
deleted
inserted
replaced
42868:96ddf83fc267 | 42869:62eabdf91f85 |
---|---|
38 | 38 |
39 pub trait SliceExt { | 39 pub trait SliceExt { |
40 fn trim_end(&self) -> &Self; | 40 fn trim_end(&self) -> &Self; |
41 fn trim_start(&self) -> &Self; | 41 fn trim_start(&self) -> &Self; |
42 fn trim(&self) -> &Self; | 42 fn trim(&self) -> &Self; |
43 fn drop_prefix(&self, needle: &Self) -> Option<&Self>; | |
43 } | 44 } |
44 | 45 |
45 fn is_not_whitespace(c: &u8) -> bool { | 46 fn is_not_whitespace(c: &u8) -> bool { |
46 !(*c as char).is_whitespace() | 47 !(*c as char).is_whitespace() |
47 } | 48 } |
78 /// ); | 79 /// ); |
79 /// ``` | 80 /// ``` |
80 fn trim(&self) -> &[u8] { | 81 fn trim(&self) -> &[u8] { |
81 self.trim_start().trim_end() | 82 self.trim_start().trim_end() |
82 } | 83 } |
84 | |
85 fn drop_prefix(&self, needle: &Self) -> Option<&Self> { | |
86 if self.starts_with(needle) { | |
87 Some(&self[needle.len()..]) | |
88 } else { | |
89 None | |
90 } | |
91 } | |
83 } | 92 } |