The ONE line counter for a source buffer (#1967). Every caller that asks * "how many lines does this file have" uses it, so the coverage report never * holds two answers for the same buffer. * * Convention: a '\n' TERMINATES a line; it does not open a new one. So the * count is the number of '\n' that have at least one byte after them, plus * one. "a\nb" and "a\nb\n" both have 2 lines (the t
| 1746 | * newline still counts its last line. An empty buffer counts as 1 line, because |
| 1747 | * tree-sitter still reports row 0 for it and 1-based line maps index line 1. */ |
| 1748 | uint32_t cbm_source_line_count(const char *src, int src_len) { |
| 1749 | uint32_t n = 1; |
| 1750 | for (int i = 0; i + 1 < src_len; i++) { |
| 1751 | if (src[i] == '\n') { |
| 1752 | n++; |
| 1753 | } |
| 1754 | } |
| 1755 | return n; |
| 1756 | } |
| 1757 | |
| 1758 | /* Recovery subtraction (#963): tree-sitter error recovery plus the |
| 1759 | * ERROR-descending def walker often still extract constructs INSIDE a failed |
no outgoing calls
no test coverage detected