]> git.lizzy.rs Git - rust.git/commitdiff
Group Pattern::strip_* method together
authorLzu Tao <taolzu@gmail.com>
Sun, 14 Jun 2020 01:01:07 +0000 (01:01 +0000)
committerLzu Tao <taolzu@gmail.com>
Sun, 14 Jun 2020 01:01:07 +0000 (01:01 +0000)
src/libcore/str/pattern.rs

index 263d6b5efdff94ccac0cd2a3e511a87a272e066a..14f1f293d40d68716fd09e8ba5c6dd04db715114 100644 (file)
@@ -69,7 +69,7 @@
 /// |--------------------------|-------------------------------------------|
 /// | `&str`                   | is substring                              |
 /// | `char`                   | is contained in string                    |
-/// | `&[char]                 | any char in slice is contained in string  |
+/// | `&[char]`                | any char in slice is contained in string  |
 /// | `F: FnMut(char) -> bool` | `F` returns `true` for a char in string   |
 /// | `&&str`                  | is substring                              |
 /// | `&String`                | is substring                              |
@@ -117,6 +117,15 @@ fn is_prefix_of(self, haystack: &'a str) -> bool {
         matches!(self.into_searcher(haystack).next(), SearchStep::Match(0, _))
     }
 
+    /// Checks whether the pattern matches at the back of the haystack
+    #[inline]
+    fn is_suffix_of(self, haystack: &'a str) -> bool
+    where
+        Self::Searcher: ReverseSearcher<'a>,
+    {
+        matches!(self.into_searcher(haystack).next_back(), SearchStep::Match(_, j) if haystack.len() == j)
+    }
+
     /// Removes the pattern from the front of haystack, if it matches.
     #[inline]
     fn strip_prefix_of(self, haystack: &'a str) -> Option<&'a str> {
@@ -133,15 +142,6 @@ fn strip_prefix_of(self, haystack: &'a str) -> Option<&'a str> {
         }
     }
 
-    /// Checks whether the pattern matches at the back of the haystack
-    #[inline]
-    fn is_suffix_of(self, haystack: &'a str) -> bool
-    where
-        Self::Searcher: ReverseSearcher<'a>,
-    {
-        matches!(self.into_searcher(haystack).next_back(), SearchStep::Match(_, j) if haystack.len() == j)
-    }
-
     /// Removes the pattern from the back of haystack, if it matches.
     #[inline]
     fn strip_suffix_of(self, haystack: &'a str) -> Option<&'a str>