All Projects → azagniotov → ant-style-path-matcher

azagniotov / ant-style-path-matcher

Licence: MIT license
Concise, recursive & efficient path matcher implementation for Ant-style path patterns

Programming Languages

java
68154 projects - #9 most used programming language

Ant-style Path Matcher

Consise, recursive & efficient path matcher implementation for an Ant-style path pattern matching algorithm. There are two implementations available:

  1. AntPathMatcher
  2. 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 - matches com/test.jsp but also com/tast.jsp or com/txst.jsp
  • com/*.jsp - matches all .jsp files in the com directory
  • com/**/test.jsp - matches all test.jsp files underneath the com path
  • org/springframework/**/*.jsp - matches all .jsp files underneath the org/springframework path
  • org/**/servlet/bla.jsp - matches org/springframework/servlet/bla.jsp but also org/springframework/testing/servlet/bla.jsp and org/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:

  1. Use a custom path separator. The default is / character
  2. Ignore character case during comparison. The default is false - do not ignore
  3. 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
  4. 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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].