Debian Codegraph @

single-record.go

raw symbols SCIP
1 package csv
2
3 import (
4 "bytes"
5 "encoding/csv"
6 "strings"
7 )
8
9 //Parse a string representing one or more encoded CSV record and returns the first such record.
10 func Parse(record string) ([]string, error) {
11 reader := csv.NewReader(strings.NewReader(record))
12 result, err := reader.Read()
13 if err != nil {
14 return nil, err
15 }
16 return result, nil
17 }
18
19 //Format the specified slice as a CSV record using the default CSV encoding conventions.
20 func Format(record []string) string {
21 buffer := bytes.NewBufferString("")
22 writer := csv.NewWriter(buffer)
23 writer.Write(record)
24 writer.Flush()
25 return strings.TrimRight(buffer.String(), "\n")
26 }