Skip to content

Commit

Permalink
Merge pull request #372 from davidribyrne/dbyrne-csv-format-patch
Browse files Browse the repository at this point in the history
Patch csv-stream format
  • Loading branch information
boyter committed Jan 28, 2023
2 parents e4d1ace + e77be1a commit eb02f35
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions processor/formatters.go
Expand Up @@ -11,6 +11,7 @@ import (
"math"
"os"
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -467,11 +468,17 @@ func toOpenMetricsFiles(input chan *FileJob) string {
func toCSVStream(input chan *FileJob) string {
fmt.Println("Language,Location,Filename,Lines,Code,Comments,Blanks,Complexity,Bytes")

var quoteRegex = regexp.MustCompile("\"")

for result := range input {
// Escape quotes in location and filename then surround with quotes.
var location = "\"" + quoteRegex.ReplaceAllString(result.Location, "\"\"") + "\""
var filename = "\"" + quoteRegex.ReplaceAllString(result.Filename, "\"\"") + "\""

fmt.Println(fmt.Sprintf("%s,%s,%s,%s,%s,%s,%s,%s,%s",
result.Language,
result.Location,
result.Filename,
location,
filename,
fmt.Sprint(result.Lines),
fmt.Sprint(result.Code),
fmt.Sprint(result.Comment),
Expand Down

0 comments on commit eb02f35

Please sign in to comment.