class StepDefinitionUtil {

    public static String simulateMatchingStepDefinition(String stepName, Argument[] arguments) {
        StringBuilder builder = new StringBuilder();
        builder.append("^");

        int lastIndex = 0;
        for (Argument argument : arguments) {
            if (argument.getOffset() > lastIndex) {
                builder.append(escapeRegularExpression(stepName.substring(lastIndex, argument.getOffset())));
            }

            boolean isNumeric = StringUtils.isNotEmpty(argument.getVal()) &&
                    StringUtils.isNumeric(argument.getVal()); // isNumeric() really means areDigits()
            if (isNumeric && argument.getOffset() > 0 && stepName.charAt(argument.getOffset() - 1) == '"') {
                // If an argument is numeric but preceded by a quote, it was probably meant to be a generic string
                isNumeric = false;
            }

            if (isNumeric) {
                builder.append("(\\d+)");
            } else {
                builder.append("([^\"]*)");
            }
            lastIndex = argument.getOffset() + argument.getVal().length();
        }

        if (lastIndex < stepName.length()) {
            builder.append(escapeRegularExpression(stepName.substring(lastIndex)));
        }

        builder.append("$");
        return builder.toString();
    }

}