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/xio/util.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'skate/xio/util.go') 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