ParseMultiple just takes a separator rune

This commit is contained in:
Sasha Koshka 2024-04-28 23:02:21 -04:00
parent 19b442598d
commit c465ff6d1e
2 changed files with 9 additions and 20 deletions

View File

@ -186,9 +186,9 @@ func parseThemeIndex (reader io.Reader) (theme Theme, parents []string, err erro
// Inherits (optional)
if entry, ok := iconThemeGroup["Inherits"]; ok {
parents, err = keyValue.ParseMultipleComma (
parents, err = keyValue.ParseMultiple (
keyValue.ParseString,
entry.Value)
entry.Value, ',')
if !ok { return Theme { }, nil, err }
}
@ -220,7 +220,7 @@ func parseThemeIndex (reader io.Reader) (theme Theme, parents []string, err erro
}
func parseDirectories (listEntry keyValue.Entry, file keyValue.File) ([]Directory, error) {
names, err := keyValue.ParseMultipleComma(keyValue.ParseString, listEntry.Value)
names, err := keyValue.ParseMultiple(keyValue.ParseString, listEntry.Value, ',')
if err != nil { return nil, err }
directories := make([]Directory, len(names))
for index, name := range names {
@ -523,7 +523,7 @@ func parseIconData (path string) (Icon, error) {
// EmbeddedTextRectangle (optional)
if entry, ok := iconDataGroup["EmbeddedTextRectangle"]; ok {
embeddedTextRectangle, err := keyValue.ParseMultipleComma(keyValue.ParseInteger, entry.Value)
embeddedTextRectangle, err := keyValue.ParseMultiple(keyValue.ParseInteger, entry.Value, ',')
if len(embeddedTextRectangle) == 4 {
icon.EmbeddedTextRectangle = image.Rect (
embeddedTextRectangle[0],

View File

@ -345,22 +345,11 @@ func ParseNumeric (value string) (float64, error) {
}
// ParseMultiple parses multiple of a value type. Any value parsing function can
// be specified. The multiple values should be separated by a semicolon and the
// input string may be optionally terminated by a semicolon. Trailing empty
// strings must always be terminated with a semicolon. Semicolons in these
// values need to be escaped using \;.
func ParseMultiple[T any] (parser func (string) (T, error), value string) ([]T, error) {
return parseMultiple(parser, value, ';')
}
// ParseMultipleComma is like ParseMultiple, but uses a comma as a separator
// instead of a semicolon. This is used to parse icon theme files because the
// freedesktop people haven't yet learned the word "consistency".
func ParseMultipleComma[T any] (parser func (string) (T, error), value string) ([]T, error) {
return parseMultiple(parser, value, ',')
}
func parseMultiple[T any] (parser func (string) (T, error), value string, sep rune) ([]T, error) {
// be specified. The multiple values should be separated by a separator and the
// input string may be optionally terminated by a separator. Trailing empty
// strings must always be terminated with a separator. Separators in these
// values need to be escaped using \<sep>.
func ParseMultiple[T any] (parser func (string) (T, error), value string, sep rune) ([]T, error) {
values := []T { }
builder := strings.Builder { }