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

Function lineCSVParseFast

io.go:851–886  ·  view source on GitHub ↗

Fast CSV parser for simple cases (no quotes, no escaping) Falls back to standard parser if needed

(s string, sep rune)

Source from the content-addressed store, hash-verified

849// Fast CSV parser for simple cases (no quotes, no escaping)
850// Falls back to standard parser if needed
851func lineCSVParseFast(s string, sep rune) ([]string, error) {
852 // Quick check if line contains quotes (needs full parser)
853 hasQuotes := false
854 for i := 0; i < len(s); i++ {
855 if s[i] == '"' {
856 hasQuotes = true
857 break
858 }
859 }
860
861 // Use fast path for simple CSV lines
862 if !hasQuotes {
863 // Count separators to pre-allocate slice
864 sepCount := 0
865 for i := 0; i < len(s); i++ {
866 if rune(s[i]) == sep {
867 sepCount++
868 }
869 }
870
871 result := make([]string, 0, sepCount+1)
872 start := 0
873 for i := 0; i < len(s); i++ {
874 if rune(s[i]) == sep {
875 result = append(result, s[start:i])
876 start = i + 1
877 }
878 }
879 // Add last field
880 result = append(result, s[start:])
881 return result, nil
882 }
883
884 // Fall back to standard parser for complex cases
885 return lineCSVParse(s, sep)
886}
887
888// add displayable(according to user's input argument) RowArray(covert line to array) To Buffer
889func addDRToBuffer(b *Buffer, line string, showNum, hideNum []int) error {

Callers 3

loadFileToBufferAsyncFunction · 0.85
loadPipeToBufferAsyncFunction · 0.85
addDRToBufferFunction · 0.85

Calls 1

lineCSVParseFunction · 0.85

Tested by

no test coverage detected