about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libcollections/str.rs4
-rw-r--r--src/libcore/str/pattern.rs9
2 files changed, 5 insertions, 8 deletions
diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs
index 6be46855fe6..7e72ad1569a 100644
--- a/src/libcollections/str.rs
+++ b/src/libcollections/str.rs
@@ -483,9 +483,7 @@ impl str {
     /// considered to be
     /// boundaries.
     ///
-    /// # Panics
-    ///
-    /// Panics if `index` is greater than `self.len()`.
+    /// Returns `false` if `index` is greater than `self.len()`.
     ///
     /// # Examples
     ///
diff --git a/src/libcore/str/pattern.rs b/src/libcore/str/pattern.rs
index dccdaa9120d..707f7fcf2ab 100644
--- a/src/libcore/str/pattern.rs
+++ b/src/libcore/str/pattern.rs
@@ -513,17 +513,16 @@ impl<'a, 'b> Pattern<'a> for &'b str {
     /// Checks whether the pattern matches at the front of the haystack
     #[inline]
     fn is_prefix_of(self, haystack: &'a str) -> bool {
-        // Use `as_bytes` so that we can slice through a character in the haystack.
-        // Since self is always valid UTF-8, this can't result in a false positive.
-        self.len() <= haystack.len() &&
-            self.as_bytes() == &haystack.as_bytes()[..self.len()]
+        haystack.is_char_boundary(self.len()) &&
+            self == &haystack[..self.len()]
     }
 
     /// Checks whether the pattern matches at the back of the haystack
     #[inline]
     fn is_suffix_of(self, haystack: &'a str) -> bool {
         self.len() <= haystack.len() &&
-            self.as_bytes() == &haystack.as_bytes()[haystack.len() - self.len()..]
+            haystack.is_char_boundary(haystack.len() - self.len()) &&
+            self == &haystack[haystack.len() - self.len()..]
     }
 }