1 | |
package org.jbehave.core.parsers; |
2 | |
|
3 | |
import java.util.regex.Matcher; |
4 | |
import java.util.regex.Pattern; |
5 | |
|
6 | |
import org.jbehave.core.model.StepPattern; |
7 | |
import org.jbehave.core.steps.StepType; |
8 | |
|
9 | |
public class RegexStepMatcher implements StepMatcher { |
10 | |
|
11 | |
private final Pattern regexPattern; |
12 | |
private final String[] parameterNames; |
13 | |
private final StepPattern stepPattern; |
14 | |
private Matcher matcher; |
15 | |
|
16 | 111 | public RegexStepMatcher(StepType stepType, String annotatedPattern, Pattern regexPattern, String[] parameterNames) { |
17 | 111 | this.regexPattern = regexPattern; |
18 | 111 | this.parameterNames = parameterNames; |
19 | 111 | this.stepPattern = new StepPattern(stepType, annotatedPattern, regexPattern.pattern()); |
20 | 111 | } |
21 | |
|
22 | |
public boolean matches(String stepWithoutStartingWord){ |
23 | 31 | matcher(stepWithoutStartingWord); |
24 | 31 | return matcher.matches(); |
25 | |
} |
26 | |
|
27 | |
public boolean find(String stepWithoutStartingWord){ |
28 | 75 | matcher(stepWithoutStartingWord); |
29 | 75 | return matcher.find(); |
30 | |
} |
31 | |
|
32 | |
public String parameter(int matchedPosition) { |
33 | 44 | return matcher.group(matchedPosition); |
34 | |
} |
35 | |
|
36 | |
private void matcher(String patternToMatch){ |
37 | 106 | matcher = regexPattern.matcher(patternToMatch); |
38 | 106 | } |
39 | |
|
40 | |
public String[] parameterNames(){ |
41 | 99 | return parameterNames; |
42 | |
} |
43 | |
|
44 | |
public StepPattern pattern() { |
45 | 13 | return stepPattern; |
46 | |
} |
47 | |
} |