Documentation
¶
Overview ¶
Package match provides a simple pattern matcher with unicode support.
Index ¶
- func Allowable(pattern string) (min, max string)
- func IsPattern(str string) bool
- func Match(str, pattern string) bool
- func MatchLimit(str, pattern string, maxcomp int) (matched, stopped bool)
- func MatchLimitNoCase(str, pattern string, maxcomp int) (matched, stopped bool)
- func MatchNoCase(str, pattern string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Allowable ¶
Allowable parses the pattern and determines the minimum and maximum allowable values that the pattern can represent. When the max cannot be determined, 'true' will be returned for infinite.
func Match ¶
Match returns true if str matches pattern. This is a very simple wildcard match where '*' matches on any number characters and '?' matches on any one character.
pattern:
{ term }
term:
'*' matches any sequence of non-Separator characters '?' matches any single non-Separator character c matches character c (c != '*', '?', '\\') '\\' c matches character c
默认保持大小写敏感, 不对匹配复杂度设置上限.
func MatchLimit ¶
MatchLimit is the same as Match but will limit the complexity of the match operation. This is to avoid long running matches, specifically to avoid ReDos attacks from arbritary inputs.
How it works: The underlying match routine is recursive and may call itself when it encounters a sandwiched wildcard pattern, such as: `user:*:name`. Everytime it calls itself a counter is incremented. The operation is stopped when counter > maxcomp*len(str). 大小写敏感匹配与忽略大小写入口共用预算规则, 超限时通过 stopped 标识.
func MatchLimitNoCase ¶ added in v1.3.7
MatchLimitNoCase 使用与 MatchLimit 相同的复杂度预算, 仅忽略 ASCII 字母大小写. 超出预算时返回 stopped, 调用方应将其与普通不匹配区分.
func MatchNoCase ¶ added in v1.3.7
MatchNoCase is the same as Match but performs a case-insensitive match. Such that string "Hello World" with match with lower case pattern "hello*" 仅忽略 ASCII 字母大小写, 其他 Unicode 字符仍按原值匹配.
Types ¶
This section is empty.