Returns the index of the first occurrence of the pattern string in the text string.
(&self, txt: &str)
| 33 | /// Returns the index of the first occurrence of the pattern string |
| 34 | /// in the text string. |
| 35 | pub fn search(&self, txt: &str) -> Option<usize> { |
| 36 | let dfa = self.dfa.as_slice(); |
| 37 | let M = self.M; |
| 38 | let N = txt.len(); |
| 39 | let mut i = 0; |
| 40 | let mut j = 0; |
| 41 | while i < N && j < M { |
| 42 | j = dfa[byte_at(txt, i)][j]; |
| 43 | i += 1; |
| 44 | } |
| 45 | if j == M { |
| 46 | Some(i - M) |
| 47 | } else { |
| 48 | None |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | impl From<&str> for KMP { |
no test coverage detected