Skip to content

Commit

Permalink
Use encoding/csv to write csv, like a sensible person would
Browse files Browse the repository at this point in the history
  • Loading branch information
dr2chase committed Jun 12, 2019
1 parent 3a7eb68 commit 44cb621
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions solve_inlines.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,26 +207,13 @@ Because solving for the best/worst inlines can be time-consuming, %s also suppor
vstore := make([]float64, 1+len(inlines))
// Use fillRow because thus only one copy of the RNG selection.
fillRow(int64(seed), int32(threshold), vstore, -1)
csvw := csv.NewWriter(os.Stdout)
for i, l := range inlines {
if vstore[i] > 0 {
value := ""
for j, s := range l.line {
a := s
if strings.Contains(s, ",") || len(s) > 0 && s[0] == '"' {
// Quoting is required for CSV.
if strings.ContainsAny(s, "\"") {
s = strings.Replace(s, "\"", "\"\"", -1)
}
a = "\"" + s + "\""
}
if j > 0 {
value += ","
}
value += fmt.Sprintf("%v", a)
}
fmt.Println(value)
csvw.Write(l.line)
}
}
csvw.Flush()
return
}

Expand Down

0 comments on commit 44cb621

Please sign in to comment.