Reverse find, starting from the given cursor If found, returns a Cursor pointing to the location, and the number of characters traversed
(&self, start: Cursor, pattern: u8)
| 165 | // Reverse find, starting from the given cursor |
| 166 | // If found, returns a Cursor pointing to the location, and the number of characters traversed |
| 167 | fn rfind(&self, start: Cursor, pattern: u8) -> Option<(Cursor, usize)> { |
| 168 | // Number of characters traversed |
| 169 | let mut ntraversed: usize = 0; |
| 170 | let mut cursor = start; |
| 171 | loop { |
| 172 | if let Some(c) = self.previous(cursor) { |
| 173 | cursor = c; |
| 174 | } else { |
| 175 | break None; |
| 176 | } |
| 177 | |
| 178 | // Count characters. NOTE: Assumes ASCII |
| 179 | ntraversed += 1; |
| 180 | |
| 181 | // Get the byte at this location |
| 182 | if self.at(cursor) == pattern { |
| 183 | break Some((cursor, ntraversed)); |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | struct Buffer<'a>(&'a mut [u8], usize); |