From 595dd843d7e2e38c08b4e03b79a0531d32d778fb Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sun, 18 Aug 2013 13:57:35 +0200 Subject: [PATCH] std::str: Use CharOffsetIterator in .find() and .rfind() --- src/libstd/str.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/libstd/str.rs b/src/libstd/str.rs index ccb7349eefd7..0becd8e722ef 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -1790,10 +1790,8 @@ impl<'self> StrSlice<'self> for &'self str { if search.matches(b as char) { return Some(i) } } } else { - let mut index = 0; - for c in self.iter() { + for (index, c) in self.char_offset_iter() { if search.matches(c) { return Some(index); } - index += c.len_utf8_bytes(); } } @@ -1807,15 +1805,14 @@ impl<'self> StrSlice<'self> for &'self str { /// `Some` containing the byte index of the last matching character /// or `None` if there is no match fn rfind(&self, search: C) -> Option { - let mut index = self.len(); if search.only_ascii() { + let mut index = self.len(); for b in self.byte_rev_iter() { index -= 1; if search.matches(b as char) { return Some(index); } } } else { - for c in self.rev_iter() { - index -= c.len_utf8_bytes(); + for (index, c) in self.char_offset_rev_iter() { if search.matches(c) { return Some(index); } } }