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
repositories {
mavenCentral()
}
dependencies {
compile("io.github.azagniotov:ant-style-path-matcher:1.0.0")
}
com/t?st.jsp
- matchescom/test.jsp
but alsocom/tast.jsp
orcom/txst.jsp
com/*.jsp
- matches all.jsp
files in thecom
directorycom/**/test.jsp
- matches alltest.jsp
files underneath thecom
pathorg/springframework/**/*.jsp
- matches all.jsp
files underneath theorg/springframework
pathorg/**/servlet/bla.jsp
- matchesorg/springframework/servlet/bla.jsp
but alsoorg/springframework/testing/servlet/bla.jsp
andorg/servlet/bla.jsp
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
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
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
- 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
MIT