mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-18 04:51:05 +01:00
continued refactoring, added more tests, better error handling
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user