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 判断 str 是否匹配 pattern; '*' 匹配任意字符序列, '?' 匹配任意单个字符.
pattern:
{ term }
term:
'*' 匹配任意字符序列, 包括路径分隔符 '?' 匹配任意单个字符, 包括路径分隔符 c matches character c (c != '*', '?', '\\') '\\' c matches character c
默认保持大小写敏感, 不对匹配复杂度设置上限.
func MatchLimit ¶
MatchLimit 与 Match 类似, 但会限制匹配复杂度, 避免任意输入造成长时间匹配或 ReDoS 攻击.
How it works: The underlying match routine is recursive and may call itself when it encounters a sandwiched wildcard pattern, such as: `user:*:name`. 每次递归调用都会增加计数器. 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. 例如, 字符串 "Hello World" 可以匹配小写模式 "hello*". 仅忽略 ASCII 字母大小写, 其他 Unicode 字符仍按原值匹配.
Types ¶
This section is empty.