From ab072dda62b2b184666fbce0ed845ba17e54ff05 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Wed, 26 May 2021 23:24:49 +0200 Subject: fix xio map generation --- skate/cmd/skate-conv/main.go | 1 + skate/xio/util.go | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/skate/cmd/skate-conv/main.go b/skate/cmd/skate-conv/main.go index 10e1265..a2c85a3 100644 --- a/skate/cmd/skate-conv/main.go +++ b/skate/cmd/skate-conv/main.go @@ -45,6 +45,7 @@ func main() { case "oled": f = openLibraryEditionToRelease if *extraOpenLibraryAuthorMapping != "" { + log.Printf("loading author mapping ...") f, err := os.Open(*extraOpenLibraryAuthorMapping) if err != nil { log.Fatal(err) diff --git a/skate/xio/util.go b/skate/xio/util.go index 681f260..19651f4 100644 --- a/skate/xio/util.go +++ b/skate/xio/util.go @@ -23,24 +23,27 @@ func OpenTwo(f1, f2 string) (g1, g2 *os.File, err error) { // mapping. func TabsToMap(r io.Reader, sep string, kCol, vCol int) (map[string]string, error) { var ( - br = bufio.NewReader(r) - m = make(map[string]string) + br = bufio.NewReader(r) + m = make(map[string]string) + line, k, v string + fields []string + err error ) for { - line, err := br.ReadString('\n') + line, err = br.ReadString('\n') if err == io.EOF { return m, nil } if err != nil { return nil, err } - fields := strings.Split(line, sep) - if len(fields) <= kCol && len(fields) <= vCol { - k := strings.TrimSpace(fields[kCol-1]) - v := strings.TrimSpace(fields[vCol-1]) + fields = strings.Split(line, sep) + if len(fields) > kCol-1 && len(fields) > vCol-1 { + k = strings.TrimSpace(fields[kCol-1]) + v = strings.TrimSpace(fields[vCol-1]) m[k] = v } else { - return nil, fmt.Errorf("invalid line: %v", line) + return nil, fmt.Errorf("invalid line: %v (%v fields, %v, %v)", line, len(fields), kCol, vCol) } } return m, nil -- cgit v1.2.3