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

pro.verron.officestamper.core.Matcher Maven / Gradle / Ivy

Go to download

Office-stamper is a Java template engine for docx documents, forked from org.wickedsource.docx-stamper

There is a newer version: 2.6.0
Show newest version
package pro.verron.officestamper.core;


/**
 * The Matcher class provides methods to match and strip expressions based on a specified prefix and suffix.
 * The match()
 * method checks if an expression starts with the prefix
 * and ends with the suffix.
 * The strip()
 * method removes the prefix and suffix from an expression
 * and returns the inner part.
 */
public record Matcher(
        String prefix,
        String suffix
) {

    /**
     * Checks if the given expression matches the specified criteria.
     *
     * @param expression the expression to be matched.
     * @return {@code true} if the expression starts with the prefix
     * and ends with the suffix,
     * {@code false} otherwise.
     */

    public boolean match(String expression) {
        return expression.startsWith(prefix)
               && expression.endsWith(suffix);
    }

    /**
     * Strips the prefix and suffix from the given expression and returns the inner part.
     *
     * @param expression the expression to be stripped.
     * @return the inner part of the expression after stripping the prefix and suffix.
     */
    public String strip(String expression) {
        int start = prefix.length();
        int end = expression.length() - suffix.length();
        return expression.substring(start, end);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy