MCPcopy Create free account
hub / github.com/codechenx/FastTableViewer / lineCSVParse

Function lineCSVParse

io.go:833–847  ·  view source on GitHub ↗

use go csv library to parse a string line into csv format Optimized version with reusable reader

(s string, sep rune)

Source from the content-addressed store, hash-verified

831// use go csv library to parse a string line into csv format
832// Optimized version with reusable reader
833func lineCSVParse(s string, sep rune) ([]string, error) {
834 r := csv.NewReader(strings.NewReader(s))
835 r.Comma = sep
836 r.LazyQuotes = true
837 r.ReuseRecord = true //reuse backing array for performance
838 //r.TrimLeadingSpace = true //disable, because it will remove NULL item and cause issue.
839 record, err := r.Read()
840 if err != nil {
841 return nil, err
842 }
843 //make a copy since ReuseRecord=true reuses the backing array
844 result := make([]string, len(record))
845 copy(result, record)
846 return result, err
847}
848
849// Fast CSV parser for simple cases (no quotes, no escaping)
850// Falls back to standard parser if needed

Callers 3

lineCSVParseFastFunction · 0.85
Test_lineCSVParseFunction · 0.85
TestLineCSVParseFunction · 0.85

Calls

no outgoing calls

Tested by 2

Test_lineCSVParseFunction · 0.68
TestLineCSVParseFunction · 0.68