continued refactoring, added more tests, better error handling

This commit is contained in:
2022-10-02 14:22:31 +02:00
parent 66c4b68036
commit e6723a6951
9 changed files with 244 additions and 41 deletions

View File

@@ -20,6 +20,7 @@ package lib
import (
"bufio"
"fmt"
"github.com/alecthomas/repr"
"io"
"regexp"
"strings"
@@ -59,7 +60,7 @@ func parseFile(input io.Reader, pattern string) Tabdata {
scanner = bufio.NewScanner(input)
for scanner.Scan() {
line := scanner.Text()
line := strings.TrimSpace(scanner.Text())
values := []string{}
patternR, err := regexp.Compile(pattern)
@@ -109,22 +110,18 @@ func parseFile(input io.Reader, pattern string) Tabdata {
// done
hadFirst = true
}
// if Debug {
// fmt.Println(data.headerIndices)
// }
} else {
// data processing
if len(pattern) > 0 {
//fmt.Println(patternR.MatchString(line))
if !patternR.MatchString(line) {
continue
}
}
idx := 0 // we cannot use the header index, because we could exclude columns
for _, index := range data.headerIndices {
value := ""
if index["end"] == 0 {
value = string(line[index["beg"]:])
} else {
@@ -159,5 +156,9 @@ func parseFile(input io.Reader, pattern string) Tabdata {
die(scanner.Err())
}
if Debug {
repr.Print(data)
}
return data
}