Minor key/value parsing fixes

This commit is contained in:
Sasha Koshka 2024-04-27 20:16:46 -04:00
parent e3b2244287
commit a5d4cd727b

View File

@ -14,6 +14,7 @@ package keyValue
import "io" import "io"
import "fmt" import "fmt"
import "bufio" import "bufio"
import "errors"
import "strings" import "strings"
import "strconv" import "strconv"
import "unicode" import "unicode"
@ -65,7 +66,9 @@ 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 err != nil { return nil, err } if errors.Is(err, io.EOF) { return file, nil }
if err != nil { return nil, err }
line = strings.TrimSpace(line) line = strings.TrimSpace(line)
switch { switch {
@ -167,8 +170,10 @@ func parseEntry (line string) (key, val string, loc locale.Locale, err error) {
} }
if state != getVal { err = ErrInvalidEntry; return } if state != getVal { err = ErrInvalidEntry; return }
loc, err = locale.Parse(locb.String()) if locb.Len() > 0 {
if err != nil { return} loc, err = locale.Parse(locb.String())
if err != nil { return}
}
key = strings.TrimSpace(keyb.String()) key = strings.TrimSpace(keyb.String())
val = strings.TrimSpace(valb.String()) val = strings.TrimSpace(valb.String())