Minor key/value parsing fixes
This commit is contained in:
parent
e3b2244287
commit
a5d4cd727b
@ -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 errors.Is(err, io.EOF) { return file, nil }
|
||||||
if err != nil { return nil, err }
|
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 }
|
||||||
|
|
||||||
|
if locb.Len() > 0 {
|
||||||
loc, err = locale.Parse(locb.String())
|
loc, err = locale.Parse(locb.String())
|
||||||
if err != nil { return}
|
if err != nil { return}
|
||||||
|
}
|
||||||
key = strings.TrimSpace(keyb.String())
|
key = strings.TrimSpace(keyb.String())
|
||||||
val = strings.TrimSpace(valb.String())
|
val = strings.TrimSpace(valb.String())
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user