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)
| 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. |
| 146 | func 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 | } |