Lines as the reference splits them (`text.split('\n')`): a final newline * leaves one more, empty line. */
| 469 | /* Lines as the reference splits them (`text.split('\n')`): a final newline |
| 470 | * leaves one more, empty line. */ |
| 471 | static bool ti_split_lines(ti_file_t *f) { |
| 472 | int count = 1; |
| 473 | for (size_t i = 0; i < f->len; i++) { |
| 474 | count += f->text[i] == '\n'; |
| 475 | } |
| 476 | f->line_starts = cbm_alloc(CBM_MEM_CLASS_EXTRACT, (size_t)count * sizeof(size_t)); |
| 477 | if (!f->line_starts) { |
| 478 | return false; |
| 479 | } |
| 480 | int at = 0; |
| 481 | f->line_starts[at++] = 0; |
| 482 | for (size_t i = 0; i < f->len; i++) { |
| 483 | if (f->text[i] == '\n') { |
| 484 | f->line_starts[at++] = i + 1; |
| 485 | } |
| 486 | } |
| 487 | f->line_count = count; |
| 488 | return true; |
| 489 | } |
| 490 | |
| 491 | static int ti_path_compare(const void *left, const void *right) { |
| 492 | return strcmp(((const ti_file_t *)left)->path, ((const ti_file_t *)right)->path); |
no test coverage detected