use go csv library to parse a string line into csv format Optimized version with reusable reader
(s string, sep rune)
| 831 | // use go csv library to parse a string line into csv format |
| 832 | // Optimized version with reusable reader |
| 833 | func 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 |
no outgoing calls