File filter tweaks.

This commit is contained in:
Nuno Cruces 2023-06-07 14:58:46 +01:00
parent 8215f02fec
commit b90dce112e
2 changed files with 8 additions and 6 deletions

12
file.go
View file

@ -157,12 +157,14 @@ func (f FileFilters) types() []string {
res = append(res, pattern)
continue
}
ext := pattern[strings.LastIndexByte(pattern, '.')+1:]
dot := strings.LastIndexByte(pattern, '.')
if dot < 0 {
continue
}
var escape bool
var buf strings.Builder
for _, b := range []byte(removeClasses(ext)) {
for _, b := range []byte(removeClasses(pattern[dot+1:])) {
switch {
case escape:
escape = false
@ -174,9 +176,7 @@ func (f FileFilters) types() []string {
}
buf.WriteByte(b)
}
if buf.Len() > 0 {
res = append(res, buf.String())
}
res = append(res, buf.String())
}
}
if res == nil {

View file

@ -31,6 +31,7 @@ func TestFileFilters_simplify(t *testing.T) {
}{
{[]string{``}, nil},
{[]string{`*.\?`}, nil},
{[]string{`*.`}, []string{`*.`}},
{[]string{`*.png`}, []string{"*.png"}},
{[]string{`*.pn?`}, []string{"*.pn?"}},
{[]string{`*.pn;`}, []string{"*.pn?"}},
@ -91,6 +92,7 @@ func TestFileFilters_types(t *testing.T) {
want []string
}{
{[]string{``}, nil},
{[]string{`*.`}, []string{".", ""}},
{[]string{`*.png`}, []string{".", "png"}},
{[]string{`*.pn?`}, nil},
{[]string{`*.pn;`}, []string{".", "pn;"}},