Remove redundant code and support charclass without base.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
This commit is contained in:
Cyril Tovena 2021-10-05 15:16:21 +02:00
parent bd4d997bee
commit 623c3ebeec
No known key found for this signature in database
GPG key ID: FD8F768F9D633FB6
2 changed files with 4 additions and 10 deletions

View file

@ -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:

View file

@ -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