equal
deleted
inserted
replaced
72 fn trim_end_matches(&self, f: impl FnMut(u8) -> bool) -> &Self; |
72 fn trim_end_matches(&self, f: impl FnMut(u8) -> bool) -> &Self; |
73 fn trim_start_matches(&self, f: impl FnMut(u8) -> bool) -> &Self; |
73 fn trim_start_matches(&self, f: impl FnMut(u8) -> bool) -> &Self; |
74 fn trim(&self) -> &Self; |
74 fn trim(&self) -> &Self; |
75 fn drop_prefix(&self, needle: &Self) -> Option<&Self>; |
75 fn drop_prefix(&self, needle: &Self) -> Option<&Self>; |
76 fn split_2(&self, separator: u8) -> Option<(&[u8], &[u8])>; |
76 fn split_2(&self, separator: u8) -> Option<(&[u8], &[u8])>; |
|
77 fn split_2_by_slice(&self, separator: &[u8]) -> Option<(&[u8], &[u8])>; |
77 } |
78 } |
78 |
79 |
79 impl SliceExt for [u8] { |
80 impl SliceExt for [u8] { |
80 fn trim_end(&self) -> &[u8] { |
81 fn trim_end(&self) -> &[u8] { |
81 self.trim_end_matches(|byte| byte.is_ascii_whitespace()) |
82 self.trim_end_matches(|byte| byte.is_ascii_whitespace()) |
131 fn split_2(&self, separator: u8) -> Option<(&[u8], &[u8])> { |
132 fn split_2(&self, separator: u8) -> Option<(&[u8], &[u8])> { |
132 let mut iter = self.splitn(2, |&byte| byte == separator); |
133 let mut iter = self.splitn(2, |&byte| byte == separator); |
133 let a = iter.next()?; |
134 let a = iter.next()?; |
134 let b = iter.next()?; |
135 let b = iter.next()?; |
135 Some((a, b)) |
136 Some((a, b)) |
|
137 } |
|
138 |
|
139 fn split_2_by_slice(&self, separator: &[u8]) -> Option<(&[u8], &[u8])> { |
|
140 if let Some(pos) = find_slice_in_slice(self, separator) { |
|
141 Some((&self[..pos], &self[pos + separator.len()..])) |
|
142 } else { |
|
143 None |
|
144 } |
136 } |
145 } |
137 } |
146 } |
138 |
147 |
139 pub trait Escaped { |
148 pub trait Escaped { |
140 /// Return bytes escaped for display to the user |
149 /// Return bytes escaped for display to the user |