Split the line into fields.
| 232 | |
| 233 | // Split the line into fields. |
| 234 | void splitSplitLine(splitLine_t * line, int maxSplits) |
| 235 | { |
| 236 | line->numFields = 0; |
| 237 | int fieldStart = 0; |
| 238 | // replace the newline with a tab so that it works like the rest of the fields. |
| 239 | line->buffer[line->bufLen-1] = '\t'; |
| 240 | for (int i=0; i<line->bufLen; ++i) |
| 241 | { |
| 242 | if (line->buffer[i] == '\t') |
| 243 | { |
| 244 | line->fields[line->numFields] = line->buffer + fieldStart; |
| 245 | line->numFields += 1; |
| 246 | if (line->numFields == maxSplits) break; |
| 247 | line->buffer[i] = 0; |
| 248 | // Get ready for the next iteration. |
| 249 | fieldStart = i+1; |
| 250 | } |
| 251 | } |
| 252 | // replace the tab at the end of the line with a null char to terminate the final string. |
| 253 | line->buffer[line->bufLen-1] = 0; |
| 254 | line->split = true; |
| 255 | } |
| 256 | |
| 257 | // Unsplit the fields back into a single string. |
| 258 | // This will mung the strings, so only call this when all processing on the line is done. |
no outgoing calls
no test coverage detected