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 | 101 | public RegexStepMatcher(StepType stepType, String annotatedPattern, Pattern regexPattern, String[] parameterNames) { |
17 | 101 | this.regexPattern = regexPattern; |
18 | 101 | this.parameterNames = parameterNames; |
19 | 101 | this.stepPattern = new StepPattern(stepType, annotatedPattern, regexPattern.pattern()); |
20 | 101 | } |
21 | |
|
22 | |
public boolean matches(String stepWithoutStartingWord){ |
23 | 28 | matcher(stepWithoutStartingWord); |
24 | 28 | return matcher.matches(); |
25 | |
} |
26 | |
|
27 | |
public boolean find(String stepWithoutStartingWord){ |
28 | 62 | matcher(stepWithoutStartingWord); |
29 | 62 | return matcher.find(); |
30 | |
} |
31 | |
|
32 | |
public String parameter(int matchedPosition) { |
33 | 40 | return matcher.group(matchedPosition); |
34 | |
} |
35 | |
|
36 | |
private void matcher(String patternToMatch){ |
37 | 90 | matcher = regexPattern.matcher(patternToMatch); |
38 | 90 | } |
39 | |
|
40 | |
public String[] parameterNames(){ |
41 | 93 | return parameterNames; |
42 | |
} |
43 | |
|
44 | |
public StepPattern pattern() { |
45 | 10 | return stepPattern; |
46 | |
} |
47 | |
} |