diff options
author | Martin Czygan <martin.czygan@gmail.com> | 2021-05-26 23:24:49 +0200 |
---|---|---|
committer | Martin Czygan <martin.czygan@gmail.com> | 2021-05-26 23:24:49 +0200 |
commit | ab072dda62b2b184666fbce0ed845ba17e54ff05 (patch) | |
tree | 9f5a92d94ca3324cd6a3181700efb6ede363b9cb | |
parent | 60fcc65be3acf78c1b3163f50a6c31b62d6a6560 (diff) | |
download | refcat-ab072dda62b2b184666fbce0ed845ba17e54ff05.tar.gz refcat-ab072dda62b2b184666fbce0ed845ba17e54ff05.zip |
fix xio map generation
-rw-r--r-- | skate/cmd/skate-conv/main.go | 1 | ||||
-rw-r--r-- | 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 |