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