File filter tweaks.
This commit is contained in:
parent
8215f02fec
commit
b90dce112e
2 changed files with 8 additions and 6 deletions
10
file.go
10
file.go
|
@ -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,11 +176,9 @@ func (f FileFilters) types() []string {
|
|||
}
|
||||
buf.WriteByte(b)
|
||||
}
|
||||
if buf.Len() > 0 {
|
||||
res = append(res, buf.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
if res == nil {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -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;"}},
|
||||
|
|
Loading…
Reference in a new issue