MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / csv_detect_header

Function csv_detect_header

libCacheSim/traceReader/generalReader/csv.c:124–160  ·  view source on GitHub ↗

* @brief detect whether the csv trace has header, * it uses a simple algorithm: compare the number of digits and letters in the * first line, if there are more digits than letters, then the first line is not * header, otherwise, the first line is header * * @param reader * @return true * @return false */

Source from the content-addressed store, hash-verified

122 * @return false
123 */
124static bool csv_detect_header(const reader_t *reader) {
125 char first_line[1024] = {0};
126 int buf_size = read_first_line(reader, first_line, 1024);
127 assert(buf_size < 1024);
128
129 bool has_header = true;
130
131 int n_digit = 0, n_af = 0, n_letter = 0;
132 for (int i = 0; i < buf_size; i++) {
133 if (isdigit(first_line[i])) {
134 n_digit += 1;
135 } else if (isalpha(first_line[i])) {
136 n_letter += 1;
137 if ((first_line[i] <= 'f' && first_line[i] >= 'a') ||
138 (first_line[i] <= 'F' && first_line[i] >= 'A')) {
139 /* a-f can be hex number */
140 n_af += 1;
141 }
142 } else {
143 ;
144 }
145 }
146
147 if (n_digit > n_letter) {
148 has_header = false;
149 } else if (n_digit < n_letter - n_af) {
150 has_header = true;
151 }
152
153 static bool has_printed = false;
154 if (!has_printed) {
155 INFO("detect csv trace has header %d\n", has_header);
156 has_printed = true;
157 }
158
159 return has_header;
160}
161
162/**
163 * @brief check whether the trace uses the given delimiter by making sure

Callers 1

csv_setup_readerFunction · 0.85

Calls 2

read_first_lineFunction · 0.85
assertFunction · 0.85

Tested by

no test coverage detected