Compare commits
2 Commits
5b9c1ed1ef
...
8b4f77b223
Author | SHA1 | Date | |
---|---|---|---|
8b4f77b223 | |||
3b1620b5ef |
@ -94,7 +94,8 @@ func findTheme (name string, trail []string, warn bool, path ...string) (Theme,
|
|||||||
instances := []string { }
|
instances := []string { }
|
||||||
for _, dir := range path {
|
for _, dir := range path {
|
||||||
entries, err := os.ReadDir(dir)
|
entries, err := os.ReadDir(dir)
|
||||||
if err != nil { return Theme { }, err }
|
if err != nil { continue }
|
||||||
|
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
if entry.Name() == name {
|
if entry.Name() == name {
|
||||||
instances = append (
|
instances = append (
|
||||||
@ -143,7 +144,7 @@ func findTheme (name string, trail []string, warn bool, path ...string) (Theme,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if warn {
|
if warn {
|
||||||
log.Printf (
|
log.Printf (
|
||||||
"xdg: could not parse inherited theme %s: %v",
|
"xdg: could not parse inherited theme '%s': %v",
|
||||||
parent, err)
|
parent, err)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
|
@ -66,7 +66,7 @@ func Parse (reader io.Reader) (File, error) {
|
|||||||
var specifiedValues map[string] struct { }
|
var specifiedValues map[string] struct { }
|
||||||
for {
|
for {
|
||||||
line, err := buffer.ReadString('\n')
|
line, err := buffer.ReadString('\n')
|
||||||
if errors.Is(err, io.EOF) { return file, nil }
|
if errors.Is(err, io.EOF) { break }
|
||||||
if err != nil { return nil, err }
|
if err != nil { return nil, err }
|
||||||
|
|
||||||
line = strings.TrimSpace(line)
|
line = strings.TrimSpace(line)
|
||||||
@ -109,15 +109,20 @@ func Parse (reader io.Reader) (File, error) {
|
|||||||
group[key] = entry
|
group[key] = entry
|
||||||
} else {
|
} else {
|
||||||
// default value
|
// default value
|
||||||
_, exists := group[key]
|
_, specified := specifiedValues[key]
|
||||||
if exists { return nil, ErrDuplicateEntry }
|
if specified { return nil, ErrDuplicateEntry }
|
||||||
entry := newEntry()
|
|
||||||
|
entry, exists := group[key]
|
||||||
|
if !exists { entry = newEntry() }
|
||||||
|
|
||||||
entry.Value = value
|
entry.Value = value
|
||||||
group[key] = entry
|
group[key] = entry
|
||||||
specifiedValues[key] = struct { } { }
|
specifiedValues[key] = struct { } { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return file, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newEntry () Entry {
|
func newEntry () Entry {
|
||||||
|
@ -168,3 +168,57 @@ File {
|
|||||||
"Icon": testEntry("fooview-new"),
|
"Icon": testEntry("fooview-new"),
|
||||||
},
|
},
|
||||||
})}
|
})}
|
||||||
|
|
||||||
|
func TestParseLocalized (test *testing.T) {
|
||||||
|
testParseString(test, `
|
||||||
|
[Group 0]
|
||||||
|
Name=something
|
||||||
|
Name[xx_XX]=other thing
|
||||||
|
Name[yy_YY]=another thing
|
||||||
|
Name[zz_ZZ]=yet another thing
|
||||||
|
[Group 1]
|
||||||
|
Name[xx_XX]=other thing
|
||||||
|
Name[yy_YY]=another thing
|
||||||
|
Name=something
|
||||||
|
Name[zz_ZZ]=yet another thing
|
||||||
|
`,
|
||||||
|
File {
|
||||||
|
"Group 0": Group {
|
||||||
|
"Name": Entry {
|
||||||
|
Value: "something",
|
||||||
|
Localized: map[locale.Locale] string {
|
||||||
|
locale.Locale {
|
||||||
|
Lang: "xx",
|
||||||
|
Country: "XX",
|
||||||
|
}: "other thing",
|
||||||
|
locale.Locale {
|
||||||
|
Lang: "yy",
|
||||||
|
Country: "YY",
|
||||||
|
}: "another thing",
|
||||||
|
locale.Locale {
|
||||||
|
Lang: "zz",
|
||||||
|
Country: "ZZ",
|
||||||
|
}: "yet another thing",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Group 1": Group {
|
||||||
|
"Name": Entry {
|
||||||
|
Value: "something",
|
||||||
|
Localized: map[locale.Locale] string {
|
||||||
|
locale.Locale {
|
||||||
|
Lang: "xx",
|
||||||
|
Country: "XX",
|
||||||
|
}: "other thing",
|
||||||
|
locale.Locale {
|
||||||
|
Lang: "yy",
|
||||||
|
Country: "YY",
|
||||||
|
}: "another thing",
|
||||||
|
locale.Locale {
|
||||||
|
Lang: "zz",
|
||||||
|
Country: "ZZ",
|
||||||
|
}: "yet another thing",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})}
|
||||||
|
Loading…
Reference in New Issue
Block a user