-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfilters.go
27 lines (23 loc) · 892 Bytes
/
filters.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package addic7ed
import (
"regexp"
"strings"
)
// WithLanguage is a filter first-class function, used to keep subtitle with given language
func WithLanguage(lang string) func(s Subtitle) bool {
return func(s Subtitle) bool {
return strings.EqualFold(strings.TrimSpace(s.Language), strings.TrimSpace(lang))
}
}
// WithVersion is a filter first-class function, used to keep subtitle with given subtitle version
func WithVersion(version string) func(s Subtitle) bool {
return func(s Subtitle) bool {
return strings.EqualFold(strings.TrimSpace(s.Version), strings.TrimSpace(version))
}
}
// WithVersionRegexp is a filter first-class function, used to keep subtitle with given subtitle version identified by a regex
func WithVersionRegexp(version *regexp.Regexp) func(s Subtitle) bool {
return func(s Subtitle) bool {
return version.MatchString(strings.TrimSpace(s.Version))
}
}