mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Remove redundant code and support charclass without base.
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
This commit is contained in:
parent
bd4d997bee
commit
623c3ebeec
|
@ -80,9 +80,6 @@ func findSetMatches(re *syntax.Regexp, base string) []string {
|
|||
return found
|
||||
}
|
||||
case syntax.OpCharClass:
|
||||
if len(base) == 0 {
|
||||
return nil
|
||||
}
|
||||
if len(re.Rune) == 1 {
|
||||
return []string{base + string(re.Rune)}
|
||||
}
|
||||
|
@ -99,13 +96,10 @@ func findSetMatches(re *syntax.Regexp, base string) []string {
|
|||
}
|
||||
for i := 0; i < len(re.Rune); i = i + 2 {
|
||||
lo, hi := re.Rune[i], re.Rune[i+1]
|
||||
if hi == lo {
|
||||
matches = append(matches, base+string(hi))
|
||||
} else {
|
||||
for c := lo; c <= hi; c++ {
|
||||
matches = append(matches, base+string(c))
|
||||
}
|
||||
for c := lo; c <= hi; c++ {
|
||||
matches = append(matches, base+string(c))
|
||||
}
|
||||
|
||||
}
|
||||
return matches
|
||||
default:
|
||||
|
|
|
@ -116,7 +116,7 @@ func TestFindSetMatches(t *testing.T) {
|
|||
{"bar|b|buzz", []string{"bar", "b", "buzz"}},
|
||||
// Simple sets containing escaped characters.
|
||||
{"fo\\.o|bar\\?|\\^baz", []string{"fo.o", "bar?", "^baz"}},
|
||||
|
||||
{"[abc]d", []string{"ad", "bd", "cd"}},
|
||||
// high low charset different => A(B[CD]|EF)|BC[XY]
|
||||
{"ABC|ABD|AEF|BCX|BCY", []string{"ABC", "ABD", "AEF", "BCX", "BCY"}},
|
||||
// triple concat
|
||||
|
|
Loading…
Reference in a new issue