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