antpath

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

*

  • Created by GoLand.
  • Brief: apache ant path matcher implement
  • User: vibrant
  • Date: 2019/03/30
  • Time: 13:10

*

  • Created by GoLand.
  • Brief: matcher fields read/write
  • User: vibrant
  • Date: 2019/04/01
  • Time: 14:57

*

  • Created by GoLand.
  • Brief: apache ant path matcher implement
  • User: vibrant
  • Date: 2019/03/31
  • Time: 13:51

*

  • Created by GoLand.
  • Brief: constant use
  • User: vibrant
  • Date: 2019/03/30
  • Time: 13:10

*

  • Created by GoLand.
  • Brief: path matcher interface
  • User: vibrant
  • Date: 2019/03/30
  • Time: 13:10

*

  • Created by GoLand.
  • Brief: matcher fields read/write
  • User: vibrant
  • Date: 2019/04/01
  • Time: 14:57

*

  • Created by GoLand.
  • Brief: matcher fields read/write
  • User: vibrant
  • Date: 2019/04/01
  • Time: 18:05

*

  • Created by GoLand.
  • Brief: apache ant path matcher implement
  • User: vibrant
  • Date: 2019/03/30
  • Time: 13:10

*

  • Created by GoLand.
  • Brief: string tool
  • User: vibrant
  • Date: 2019/03/30
  • Time: 13:10

Index

Constants

View Source
const (

	//DefaultPathSeparator Default path separator: "/"
	DefaultPathSeparator = "/"

	//CacheTurnoffThreshold
	CacheTurnoffThreshold = 65536
)
View Source
const DefaultVariablePattern = "(.*)"

DefaultVariablePattern

View Source
const EmptySpace = " "

EmptySpace

View Source
const EmptyString = ""

EmptyString

View Source
const MaxFindCount = 1 << 5

MaxFindCount default value = 32

Variables

View Source
var Asterisk rune

*

View Source
var Brackets rune

{

View Source
var GlobPattern *regexp.Regexp

GlobPattern

View Source
var QuestionMark rune

?

View Source
var VariablePattern *regexp.Regexp

pattern

View Source
var WildcardChars []rune

WildcardChars

Functions

func Bytes2Str

func Bytes2Str(b []byte) string

Bytes2Str

func HasText

func HasText(source string) bool

HasText 判断是否有值

func IsBlank

func IsBlank(source string) bool

IsBlank 判断是否存在空格

func StartsWith

func StartsWith(str, prefix string, toffset int) bool

StartsWith

func StartsWithV2

func StartsWithV2(ta, pa []byte, toffset, strLen, prefixLen int) bool

func Str2Bytes

func Str2Bytes(s string) []byte

Str2Bytes

func TokenizeToStringArray

func TokenizeToStringArray(str, delimiters string, trimTokens, ignoreEmptyTokens bool) []*string

* * Tokenize the given {@code String} into a {@code String} array via a * {@link StringTokenizer}. * <p>The given {@code delimiters} string can consist of any number of * delimiter characters. Each of those characters can be used to separate * tokens. A delimiter is always a single character; for multi-character * delimiters, consider using {@link #delimitedListToStringArray}. * @param str the {@code String} to tokenize * @param delimiters the delimiter characters, assembled as a {@code String} * (each of the characters is individually considered as a delimiter) * @param trimTokens trim the tokens via {@link String#trim()} * @param ignoreEmptyTokens omit empty tokens from the result array * (only applies to tokens that are empty after trimming; StringTokenizer * will not consider subsequent delimiters as token in the first place). * @return an array of the tokens ({@code null} if the input {@code String} * was {@code null}) * @see java.util.StringTokenizer * @see String#trim() * @see #delimitedListToStringArray

TokenizeToStringArray

func TokenizeToStringArray1

func TokenizeToStringArray1(str, delimiters string) []*string

TokenizeToStringArray1

Types

type AntPathMatcher

type AntPathMatcher struct {
	// contains filtered or unexported fields
}

AntPathMatcher implement from PathMatcher interface

func New

func New() *AntPathMatcher

* * Create a new instance with the {@link #DEFAULT_PATH_SEPARATOR}.

New

func NewS

func NewS(separator string) *AntPathMatcher

* * Create a new instance with the {@link #DEFAULT_PATH_SEPARATOR}.

NewS

func (*AntPathMatcher) Combine

func (ant *AntPathMatcher) Combine(pattern1, pattern2 string) string

@Override Combine 将pattern1和pattern2联合成一个新的pattern

func (*AntPathMatcher) ExtractPathWithinPattern

func (ant *AntPathMatcher) ExtractPathWithinPattern(pattern, path string) string

@Override ExtractPathWithinPattern

func (*AntPathMatcher) ExtractUriTemplateVariables

func (ant *AntPathMatcher) ExtractUriTemplateVariables(pattern, path string) *map[string]string

@Override ExtractUriTemplateVariables

func (*AntPathMatcher) GetPatternComparator

func (ant *AntPathMatcher) GetPatternComparator(path string) *AntPatternComparator

@Override GetPatternComparator

func (*AntPathMatcher) GetStringMatcher added in v0.0.9

func (ant *AntPathMatcher) GetStringMatcher(pattern string) *AntPathStringMatcher

func (*AntPathMatcher) IsPattern

func (ant *AntPathMatcher) IsPattern(path string) bool

@Override IsPattern

func (*AntPathMatcher) Match

func (ant *AntPathMatcher) Match(pattern, path string) bool

@Override Match

func (*AntPathMatcher) MatchStart

func (ant *AntPathMatcher) MatchStart(pattern, path string) bool

@Override MatchStart

func (*AntPathMatcher) MatchV2 added in v0.0.5

func (ant *AntPathMatcher) MatchV2(pattern, path string, tokens []*string) bool

@Override MatchV2

func (*AntPathMatcher) PatternCacheSize

func (ant *AntPathMatcher) PatternCacheSize() int64

PatternCacheSize

func (*AntPathMatcher) SetCachePatterns

func (ant *AntPathMatcher) SetCachePatterns(cachePatterns bool)

* * Specify whether to cache parsed pattern metadata for patterns passed * into this matcher's {@link #match} method. A value of {@code true} * activates an unlimited pattern cache; a value of {@code false} turns * the pattern cache off completely. * <p>Default is for the cache to be on, but with the variant to automatically * turn it off when encountering too many patterns to cache at runtime * (the threshold is 65536), assuming that arbitrary permutations of patterns * are coming in, with little chance for encountering a recurring pattern.

SetCachePatterns

func (*AntPathMatcher) SetCaseSensitive

func (ant *AntPathMatcher) SetCaseSensitive(caseSensitive bool)

* Specify whether to perform pattern matching in a case-sensitive fashion. <p>Default is {@code true}. Switch this to {@code false} for case-insensitive matching.

SetCaseSensitive 区分大小写 The default is false

func (*AntPathMatcher) SetPathSeparator

func (ant *AntPathMatcher) SetPathSeparator(pathSeparator string)

* Set the path separator to use for pattern parsing.

SetPathSeparator The default is "/",as in ant.

func (*AntPathMatcher) SetTrimTokens

func (ant *AntPathMatcher) SetTrimTokens(trimTokens bool)

* Specify whether to trim tokenized paths and patterns.

SetTrimTokens 是否去除空格 The default is false

func (*AntPathMatcher) TokenizePath

func (ant *AntPathMatcher) TokenizePath(path string) []*string

type AntPathStringMatcher

type AntPathStringMatcher struct {
	// contains filtered or unexported fields
}

* * Tests whether or not a string matches against a pattern via a {@link Pattern}. * <p>The pattern may contain special characters: '*' means zero or more characters; '?' means one and * only one character; '{' and '}' indicate a URI template pattern. For example <tt>/users/{user}</tt>.

AntPathStringMatcher

func NewDefaultStringMatcher

func NewDefaultStringMatcher(pattern string, caseSensitive bool) *AntPathStringMatcher

NewDefaultStringMatcher part match

func NewMatchesStringMatcher

func NewMatchesStringMatcher(pattern string, caseSensitive bool) *AntPathStringMatcher

NewMatchesStringMatcher full match

func (*AntPathStringMatcher) FindSubMatch

func (sm *AntPathStringMatcher) FindSubMatch(source []byte, index int) *string

FindSubMatch 子查询

func (*AntPathStringMatcher) GroupCount

func (sm *AntPathStringMatcher) GroupCount() int

GroupCount

func (*AntPathStringMatcher) MatchStrings

func (sm *AntPathStringMatcher) MatchStrings(str string, uriTemplateVariables *map[string]string) bool

* * Main entry point. * * @return {@code true} if the string matches against the pattern, or {@code false} otherwise.

MatchStrings

type AntPatternComparator

type AntPatternComparator struct {
	// contains filtered or unexported fields
}

* * The default {@link Comparator} implementation returned by * {@link #getPatternComparator(String)}. * <p>In order, the most "generic" pattern is determined by the following: * <ul> * <li>if it's null or a capture all pattern (i.e. it is equal to "/**")</li> * <li>if the other pattern is an actual match</li> * <li>if it's a catch-all pattern (i.e. it ends with "**"</li> * <li>if it's got more "*" than the other pattern</li> * <li>if it's got more "{foo}" than the other pattern</li> * <li>if it's shorter than the other pattern</li> * </ul>

AntPatternComparator

func NewDefaultAntPatternComparator

func NewDefaultAntPatternComparator(path string) *AntPatternComparator

NewDefaultAntPatternComparator

func (*AntPatternComparator) Compare

func (comparator *AntPatternComparator) Compare(pattern1, pattern2 string) int

Compare

type PathMatcher

type PathMatcher interface {

	/**
	 * Does the given {@code path} represent a pattern that can be matched
	 * by an implementation of this interface?
	 * <p>If the return value is {@code false}, then the {@link #match}
	 * method does not have to be used because direct equality comparisons
	 * on the static path Strings will lead to the same result.
	 * @param path the path String to check
	 * @return {@code true} if the given {@code path} represents a pattern
	 */
	//IsPattern
	IsPattern(path string) bool

	/**
	 * Match the given {@code path} against the given {@code pattern},
	 * according to this PathMatcher's matching strategy.
	 * @param pattern the pattern to match against
	 * @param path the path String to test
	 * @return {@code true} if the supplied {@code path} matched,
	 * {@code false} if it didn't
	 */
	//Match
	Match(pattern, path string) bool

	//Match
	MatchV2(pattern, path string, tokens []*string) bool

	//TokenizePath
	TokenizePath(path string) []*string

	// getStringMatcher
	GetStringMatcher(pattern string) *AntPathStringMatcher

	/**
	 * Match the given {@code path} against the corresponding part of the given
	 * {@code pattern}, according to this PathMatcher's matching strategy.
	 * <p>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.
	 * @param pattern the pattern to match against
	 * @param path the path String to test
	 * @return {@code true} if the supplied {@code path} matched,
	 * {@code false} if it didn't
	 */
	//MatchStart
	MatchStart(pattern, path string) bool

	/**
	 * Given a pattern and a full path, determine the pattern-mapped part.
	 * <p>This method is supposed to find out which part of the path is matched
	 * dynamically through an actual pattern, that is, it strips off a statically
	 * defined leading path from the given full path, returning only the actually
	 * pattern-matched part of the path.
	 * <p>For example: For "myroot/*.html" as pattern and "myroot/myfile.html"
	 * as full path, this method should return "myfile.html". The detailed
	 * determination rules are specified to this PathMatcher's matching strategy.
	 * <p>A simple implementation may return the given full path as-is in case
	 * of an actual pattern, and the empty String in case of the pattern not
	 * containing any dynamic parts (i.e. the {@code pattern} parameter being
	 * a static path that wouldn't qualify as an actual {@link #isPattern pattern}).
	 * A sophisticated implementation will differentiate between the static parts
	 * and the dynamic parts of the given path pattern.
	 * @param pattern the path pattern
	 * @param path the full path to introspect
	 * @return the pattern-mapped part of the given {@code path}
	 * (never {@code null})
	 */
	//ExtractPathWithinPattern
	ExtractPathWithinPattern(pattern, path string) string

	/**
	 * Given a pattern and a full path, extract the URI template variables. URI template
	 * variables are expressed through curly brackets ('{' and '}').
	 * <p>For example: For pattern "/hotels/{hotel}" and path "/hotels/1", this method will
	 * return a map containing "hotel"->"1".
	 * @param pattern the path pattern, possibly containing URI templates
	 * @param path the full path to extract template variables from
	 * @return a map, containing variable names as keys; variables values as values
	 */
	//ExtractUriTemplateVariables
	ExtractUriTemplateVariables(pattern, path string) *map[string]string

	/**
	 * Given a full path, returns a {@link Comparator} suitable for sorting patterns
	 * in order of explicitness for that path.
	 * <p>The full algorithm used depends on the underlying implementation, but generally,
	 * the returned {@code Comparator} will
	 * {@linkplain java.util.Collections#sort(java.util.List, java.util.Comparator) sort}
	 * a list so that more specific patterns come before generic patterns.
	 * @param path the full path to use for comparison
	 * @return a comparator capable of sorting patterns in order of explicitness
	 */
	//GetPatternComparator
	GetPatternComparator(path string) *AntPatternComparator

	/**
	 * Combines two patterns into a new pattern that is returned.
	 * <p>The full algorithm used for combining the two pattern depends on the underlying implementation.
	 * @param pattern1 the first pattern
	 * @param pattern2 the second pattern
	 * @return the combination of the two patterns
	 * @throws IllegalArgumentException when the two patterns cannot be combined
	 */
	//Combine
	Combine(pattern1, pattern2 string) string

	// -------------------------------  fields -------------------------- //
	//SetPathSeparator
	SetPathSeparator(pathSeparator string)
	//SetCaseSensitive
	SetCaseSensitive(caseSensitive bool)
	//SetTrimTokens
	SetTrimTokens(trimTokens bool)
	//SetCachePatterns
	SetCachePatterns(cachePatterns bool)

	// -------------------------------  fields size -------------------------- //
	//stringMatcherCache size
	PatternCacheSize() int64
}

PathMatcher

type PathSeparatorPatternCache

type PathSeparatorPatternCache struct {
	// contains filtered or unexported fields
}

* * A simple cache for patterns that depend on the configured path separator.

func NewDefaultPathSeparatorPatternCache

func NewDefaultPathSeparatorPatternCache(pathSeparator string) *PathSeparatorPatternCache

NewDefaultPathSeparatorPatternCache 构造函数

func (*PathSeparatorPatternCache) GetEndsOnDoubleWildCard

func (patternCache *PathSeparatorPatternCache) GetEndsOnDoubleWildCard() string

GetEndsOnDoubleWildCard 返回 "**"

func (*PathSeparatorPatternCache) GetEndsOnWildCard

func (patternCache *PathSeparatorPatternCache) GetEndsOnWildCard() string

GetEndsOnWildCard 返回 "*"

type PatternInfo

type PatternInfo struct {
	// contains filtered or unexported fields
}

* * Value class that holds information about the pattern, e.g. number of * occurrences of "*", "**", and "{" pattern elements.

PatternInfo

func NewDefaultPatternInfo

func NewDefaultPatternInfo(pattern string) *PatternInfo

NewDefaultPatternInfo

func (*PatternInfo) GetDoubleWildcards

func (pi *PatternInfo) GetDoubleWildcards() int

GetDoubleWildcards

func (*PatternInfo) GetLength

func (pi *PatternInfo) GetLength() int

*

  • Returns the length of the given pattern, where template variables are considered to be 1 long.

func (*PatternInfo) GetSingleWildcards

func (pi *PatternInfo) GetSingleWildcards() int

GetSingleWildcards

func (*PatternInfo) GetTotalCount

func (pi *PatternInfo) GetTotalCount() int

GetTotalCount

func (*PatternInfo) GetUriVars

func (pi *PatternInfo) GetUriVars() int

GetUriVars

func (*PatternInfo) IsLeastSpecific

func (pi *PatternInfo) IsLeastSpecific() bool

IsLeastSpecific

func (*PatternInfo) IsPrefixPattern

func (pi *PatternInfo) IsPrefixPattern() bool

IsPrefixPattern

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL