MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / detectDelimiter

Function detectDelimiter

pkg/tabular/tabular.go:146–170  ·  view source on GitHub ↗

detectDelimiter inspects the header line and picks the delimiter (comma or tab) that appears more often outside of quoted fields. sigcheck's comma output quotes every field, so a tab inside a quoted path or description must not be mistaken for a TSV separator. Defaults to comma.

(data []byte)

Source from the content-addressed store, hash-verified

144// output quotes every field, so a tab inside a quoted path or description must
145// not be mistaken for a TSV separator. Defaults to comma.
146func detectDelimiter(data []byte) rune {
147 line, _, _ := bytes.Cut(data, []byte{'\n'})
148
149 var commas, tabs int
150 inQuotes := false
151 for _, b := range line {
152 switch b {
153 case '"':
154 inQuotes = !inQuotes
155 case ',':
156 if !inQuotes {
157 commas++
158 }
159 case '\t':
160 if !inQuotes {
161 tabs++
162 }
163 }
164 }
165
166 if tabs > commas {
167 return '\t'
168 }
169 return ','
170}

Callers 1

ParseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected