aboutsummaryrefslogtreecommitdiffstats
path: root/skate
diff options
context:
space:
mode:
authorMartin Czygan <martin.czygan@gmail.com>2021-05-06 00:41:13 +0200
committerMartin Czygan <martin.czygan@gmail.com>2021-05-06 00:41:13 +0200
commit9aa0271ffc471ffd733d0f133d90821759240d53 (patch)
treea03acb0b52f34d6937bf6aff29748a8c04696c57 /skate
parent6ec4eda8da2342599c61a79e5a4e98e748a1b1c3 (diff)
downloadrefcat-9aa0271ffc471ffd733d0f133d90821759240d53.tar.gz
refcat-9aa0271ffc471ffd733d0f133d90821759240d53.zip
zippy: tweaks
Diffstat (limited to 'skate')
-rw-r--r--skate/zippy.go38
-rw-r--r--skate/zippy_test.go2
2 files changed, 24 insertions, 16 deletions
diff --git a/skate/zippy.go b/skate/zippy.go
index ad1923a..6b1c373 100644
--- a/skate/zippy.go
+++ b/skate/zippy.go
@@ -18,16 +18,19 @@ func ZippyFixed(releases, refs io.Reader, mr MatchResult, provenance string, w i
enc = json.NewEncoder(w)
keyer = makeKeyFunc("\t", 2)
grouper = func(g *zipkey.Group) error {
+ var (
+ target *Release
+ ref *Ref
+ err error
+ )
if len(g.G0) == 0 || len(g.G1) == 0 {
return nil
}
- target, err := stringToRelease(lineColumn(g.G0[0], "\t", 3))
- if err != nil {
+ if target, err = stringToRelease(cut(g.G0[0], "\t", 3)); err != nil {
return err
}
for _, line := range g.G1 {
- ref, err := stringToRef(lineColumn(line, "\t", 3))
- if err != nil {
+ if ref, err = stringToRef(cut(line, "\t", 3)); err != nil {
return err
}
var bref BiblioRef
@@ -60,16 +63,19 @@ func ZippyFixedWiki(releases, wiki io.Reader, mr MatchResult, provenance string,
enc = json.NewEncoder(w)
keyer = makeKeyFunc("\t", 2)
grouper = func(g *zipkey.Group) error {
+ var (
+ target *Release
+ wiki *MinimalCitations
+ err error
+ )
if len(g.G0) == 0 || len(g.G1) == 0 {
return nil
}
- target, err := stringToRelease(lineColumn(g.G0[0], "\t", 3))
- if err != nil {
+ if target, err = stringToRelease(cut(g.G0[0], "\t", 3)); err != nil {
return err
}
for _, line := range g.G1 {
- wiki, err := stringToWiki(lineColumn(line, "\t", 3))
- if err != nil {
+ if wiki, err = stringToWiki(cut(line, "\t", 3)); err != nil {
return err
}
var bref BiblioRef
@@ -101,16 +107,18 @@ func ZippyVerifyRefs(releases, refs io.Reader, w io.Writer) error {
enc = json.NewEncoder(w)
keyer = makeKeyFunc("\t", 2)
grouper = func(g *zipkey.Group) error {
+ var (
+ re, pivot *Release
+ err error
+ )
if len(g.G0) == 0 || len(g.G1) == 0 {
return nil
}
- pivot, err := stringToRelease(lineColumn(g.G0[0], "\t", 3))
- if err != nil {
+ if pivot, err = stringToRelease(cut(g.G0[0], "\t", 3)); err != nil {
return err
}
for _, line := range g.G1 {
- re, err := stringToRelease(lineColumn(line, "\t", 3))
- if err != nil {
+ if re, err = stringToRelease(cut(line, "\t", 3)); err != nil {
return err
}
result := Verify(pivot, re)
@@ -136,7 +144,7 @@ func ZippyVerifyRefs(releases, refs io.Reader, w io.Writer) error {
// column from fields separated by sep; column is 1-indexed.
func makeKeyFunc(sep string, column int) func(string) (string, error) {
return func(s string) (string, error) {
- if k := lineColumn(s, sep, column); k == "" {
+ if k := cut(s, sep, column); k == "" {
return k, fmt.Errorf("cannot get key: %s", s)
} else {
return k, nil
@@ -144,9 +152,9 @@ func makeKeyFunc(sep string, column int) func(string) (string, error) {
}
}
-// lineColumn returns a specific column (1-indexed, like cut) from a tabular
+// cut returns a specific column (1-indexed, like cut) from a tabular
// file, returns empty string if column is invalid.
-func lineColumn(line, sep string, column int) string {
+func cut(line, sep string, column int) string {
parts := strings.Split(strings.TrimSpace(line), sep)
if len(parts) < column {
return ""
diff --git a/skate/zippy_test.go b/skate/zippy_test.go
index 49f4a54..c966d67 100644
--- a/skate/zippy_test.go
+++ b/skate/zippy_test.go
@@ -17,7 +17,7 @@ func TestLineColumn(t *testing.T) {
{"1 2 3", "\t", 1, "1 2 3"},
}
for _, c := range cases {
- result := lineColumn(c.line, c.sep, c.column)
+ result := cut(c.line, c.sep, c.column)
if result != c.result {
t.Fatalf("got %v, want %v", result, c.result)
}