1 use std
::str::pattern
::{Pattern, SearchStep, Searcher}
;
3 use re_unicode
::{Matches, Regex}
;
5 pub struct RegexSearcher
<'r
, 't
> {
9 next_match
: Option
<(usize, usize)>,
12 impl<'r
, 't
> Pattern
<'t
> for &'r Regex
{
13 type Searcher
= RegexSearcher
<'r
, 't
>;
15 fn into_searcher(self, haystack
: &'t
str) -> RegexSearcher
<'r
, 't
> {
18 it
: self.find_iter(haystack
),
25 unsafe impl<'r
, 't
> Searcher
<'t
> for RegexSearcher
<'r
, 't
> {
27 fn haystack(&self) -> &'t
str {
32 fn next(&mut self) -> SearchStep
{
33 if let Some((s
, e
)) = self.next_match
{
34 self.next_match
= None
;
35 self.last_step_end
= e
;
36 return SearchStep
::Match(s
, e
);
38 match self.it
.next() {
40 if self.last_step_end
< self.haystack().len() {
41 let last
= self.last_step_end
;
42 self.last_step_end
= self.haystack().len();
43 SearchStep
::Reject(last
, self.haystack().len())
49 let (s
, e
) = (m
.start(), m
.end());
50 if s
== self.last_step_end
{
51 self.last_step_end
= e
;
52 SearchStep
::Match(s
, e
)
54 self.next_match
= Some((s
, e
));
55 let last
= self.last_step_end
;
56 self.last_step_end
= s
;
57 SearchStep
::Reject(last
, s
)