diff options
| author | bors <bors@rust-lang.org> | 2017-05-19 20:41:18 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-05-19 20:41:18 +0000 |
| commit | 5dfcd85fd4bae49445383baadf472fbdb414a0e6 (patch) | |
| tree | 6812e7e07285e77a85e3619139280ca3cd09b0a7 /src/libcore | |
| parent | 543691d0ebbbf9e3c996980d2b841794098e5e85 (diff) | |
| parent | 040cd6d15dcc8c1f66726293d52df93abd2e4b76 (diff) | |
| download | rust-5dfcd85fd4bae49445383baadf472fbdb414a0e6.tar.gz rust-5dfcd85fd4bae49445383baadf472fbdb414a0e6.zip | |
Auto merge of #42105 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 17 pull requests - Successful merges: #41870, #41910, #41958, #41971, #42006, #42024, #42037, #42056, #42067, #42070, #42079, #42080, #42082, #42089, #42092, #42096, #42100 - Failed merges:
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/str/pattern.rs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/libcore/str/pattern.rs b/src/libcore/str/pattern.rs index 8493afe98bc..4918e37eb35 100644 --- a/src/libcore/str/pattern.rs +++ b/src/libcore/str/pattern.rs @@ -429,7 +429,33 @@ impl<'a> DoubleEndedSearcher<'a> for CharSearcher<'a> {} /// Searches for chars that are equal to a given char impl<'a> Pattern<'a> for char { - pattern_methods!(CharSearcher<'a>, CharEqPattern, CharSearcher); + type Searcher = CharSearcher<'a>; + + #[inline] + fn into_searcher(self, haystack: &'a str) -> Self::Searcher { + CharSearcher(CharEqPattern(self).into_searcher(haystack)) + } + + #[inline] + fn is_contained_in(self, haystack: &'a str) -> bool { + if (self as u32) < 128 { + haystack.as_bytes().contains(&(self as u8)) + } else { + let mut buffer = [0u8; 4]; + self.encode_utf8(&mut buffer).is_contained_in(haystack) + } + } + + #[inline] + fn is_prefix_of(self, haystack: &'a str) -> bool { + CharEqPattern(self).is_prefix_of(haystack) + } + + #[inline] + fn is_suffix_of(self, haystack: &'a str) -> bool where Self::Searcher: ReverseSearcher<'a> + { + CharEqPattern(self).is_suffix_of(haystack) + } } ///////////////////////////////////////////////////////////////////////////// |
