| 142 | } |
| 143 | |
| 144 | fn find(&self, start: Cursor, pattern: u8) -> Option<(Cursor, usize)> { |
| 145 | // Number of characters traversed |
| 146 | let mut ntraversed: usize = 0; |
| 147 | let mut cursor = start; |
| 148 | loop { |
| 149 | if let Some(c) = self.next(cursor) { |
| 150 | cursor = c; |
| 151 | } else { |
| 152 | break None; |
| 153 | } |
| 154 | |
| 155 | // Count characters. NOTE: Assumes ASCII |
| 156 | ntraversed += 1; |
| 157 | |
| 158 | // Get the byte at this location |
| 159 | if self.at(cursor) == pattern { |
| 160 | break Some((cursor, ntraversed)); |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // Reverse find, starting from the given cursor |
| 166 | // If found, returns a Cursor pointing to the location, and the number of characters traversed |