ant-style-path-matcher
ant-style-path-matcher copied to clipboard
Concise, recursive & efficient path matcher implementation for Ant-style path patterns
Ant-style Path Matcher
Consise, recursive & efficient path matcher implementation for an Ant-style path pattern matching algorithm. There are two implementations available:
- AntPathMatcher
- AntPathMatcherArrays that does not create substrings during matching
The matcher matches URLs using the following rules:
-
?
matches one character -
*
matches zero or more characters -
**
matches zero or more directories in a path
Dependencies
Gradle
repositories {
mavenCentral()
}
dependencies {
compile("io.github.azagniotov:ant-style-path-matcher:1.0.0")
}
Examples
-
com/t?st.jsp
- matchescom/test.jsp
but alsocom/tast.jsp
orcom/txst.jsp
-
com/*.jsp
- matches all.jsp
files in thecom
directory -
com/**/test.jsp
- matches alltest.jsp
files underneath thecom
path -
org/springframework/**/*.jsp
- matches all.jsp
files underneath theorg/springframework
path -
org/**/servlet/bla.jsp
- matchesorg/springframework/servlet/bla.jsp
but alsoorg/springframework/testing/servlet/bla.jsp
andorg/servlet/bla.jsp
Complexity
The matching algorithm of AntPathMatcherArrays uses a O(N)
space complexity, since the algorithm does not create
substrings (unlike AntPathMatcher) and recurses by moving pointers on the original char arrays
Testability
The matcher has been thoroughly tested. The unit test cases have been kindly borrowed from Spring's AntPathMatcherTests
in order to achieve matcher behaviour parity, you can refer to AntPathMatcherTest to view the test cases
Configuration
The instances of this path matcher can be configured via its Builder
to:
- Use a custom path separator. The default is
/
character - Ignore character case during comparison. The default is
false
- do not ignore - Match start. Determines whether the pattern at least matches as far as the given base path goes, assuming that a full path may then match as well. The default is
false
- do a full match - Specify whether to trim tokenized paths. The default is
false
- do not trim
Credits
- Part of this README description has been kindly borrowed from Spring's
AntPathMatcher
- The path matcher configuration options have been inspired by Spring's
AntPathMatcher
License
MIT