(&self, options: FindOptions, vm: &VirtualMachine)
| 970 | |
| 971 | #[pymethod] |
| 972 | fn find(&self, options: FindOptions, vm: &VirtualMachine) -> PyResult<PyInt> { |
| 973 | let (start, end) = self.get_find_range(options.clone()); |
| 974 | |
| 975 | let sub = &options.sub; |
| 976 | |
| 977 | // returns start position for empty string |
| 978 | if sub.is_empty() { |
| 979 | return Ok(PyInt::from(start as isize)); |
| 980 | } |
| 981 | |
| 982 | let mmap = self.check_valid(vm)?; |
| 983 | let buf = &mmap.as_ref().unwrap().as_slice()[start..end]; |
| 984 | let pos = buf.windows(sub.len()).position(|window| window == sub); |
| 985 | |
| 986 | Ok(pos.map_or(PyInt::from(-1isize), |i| PyInt::from(start + i))) |
| 987 | } |
| 988 | |
| 989 | #[pymethod] |
| 990 | fn rfind(&self, options: FindOptions, vm: &VirtualMachine) -> PyResult<PyInt> { |
no test coverage detected