diff options
Diffstat (limited to 'skate')
-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 |