-
Notifications
You must be signed in to change notification settings - Fork 7
/
Filename.go
61 lines (49 loc) · 1.6 KB
/
Filename.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package ids
import (
"strings"
"github.com/inkyblackness/hacked/ss1/resource"
)
// Filename defines a wrapper for a file that is possibly language-specific.
type Filename interface {
// For returns the name of the file for the given language.
For(lang resource.Language) string
// Matches returns true if the given filename matches the described one.
Matches(filename string) bool
}
// I18nFile is for internationalized resource files - i.e., those that store resources per file.
type I18nFile [resource.LanguageCount]string
// For returns the string per language index.
func (spec I18nFile) For(lang resource.Language) string {
return spec[int(lang)]
}
// Matches returns true if the given filename matches one of the localized filenames.
func (spec I18nFile) Matches(filename string) bool {
lowercase := strings.ToLower(filename)
for _, entry := range spec {
if entry == lowercase {
return true
}
}
return false
}
// AnyLanguage is for generic resource files that are language agnostic.
type AnyLanguage string
// For returns the string itself.
func (any AnyLanguage) For(lang resource.Language) string {
return string(any)
}
// Matches returns true if the given filename matches this one.
func (any AnyLanguage) Matches(filename string) bool {
return strings.ToLower(filename) == string(any)
}
// FilenameList is a list of filenames.
type FilenameList []Filename
// Matches returns true if the given filename matches any of the contained entries.
func (list FilenameList) Matches(filename string) bool {
for _, entry := range list {
if entry.Matches(filename) {
return true
}
}
return false
}