All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cucumber.runtime.JdkPatternArgumentMatcher Maven / Gradle / Ivy

There is a newer version: 1.2.6
Show newest version
package cucumber.runtime;

import gherkin.formatter.Argument;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class JdkPatternArgumentMatcher {
    private final Pattern pattern;

    public JdkPatternArgumentMatcher(Pattern pattern) {
        this.pattern = pattern;
    }

    public List argumentsFrom(String stepName) {
        Matcher matcher = pattern.matcher(stepName);
        if (matcher.lookingAt()) {
            List arguments = new ArrayList(matcher.groupCount());
            for (int i = 1; i <= matcher.groupCount(); i++) {
                int startIndex = matcher.start(i);
                arguments.add(new Argument(startIndex == -1 ? null : startIndex, matcher.group(i)));
            }
            return arguments;
        } else {
            return null;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy