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

com.softicar.platform.common.core.java.classes.name.matcher.InternalGlobPatternToRegexConverter Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.core.java.classes.name.matcher;

/**
 * Converts a Java class name glob pattern into a regular expression.
 *
 * @see JavaClassNameGlobPatternMatcher
 * @author Oliver Richers
 */
class InternalGlobPatternToRegexConverter {

	private final String globPattern;

	public InternalGlobPatternToRegexConverter(String globPattern) {

		if (!globPattern.matches("[a-zA-Z0-9*_$\\.]+")) {
			throw new IllegalArgumentException(String.format("Illegal glob pattern: '%s'", globPattern));
		}

		this.globPattern = globPattern;
	}

	public String convert() {

		return globPattern//
			.replace(".", "\\.")
			.replaceAll("\\*\\*", "@")
			.replaceAll("\\*", "[^\\\\.]*")
			.replaceAll("@", ".*");
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy