9 list->
offsets = (
size_t *) calloc(capacity,
sizeof(
size_t));
10 if (list->
offsets == NULL)
return false;
29 size_t *original_offsets = list->
offsets;
33 memcpy(list->
offsets, original_offsets, list->
size *
sizeof(
size_t));
34 free(original_offsets);
35 if (list->
offsets == NULL)
return false;
38 assert(*cursor ==
'\n');
39 assert(cursor >= list->
start);
40 size_t newline_offset = (size_t) (cursor - list->
start + 1);
42 assert(list->
size == 0 || newline_offset > list->
offsets[list->
size - 1]);
54 if (*cursor !=
'\n') {
57 return pm_newline_list_append(list, cursor);
67 assert(cursor >= list->
start);
68 size_t offset = (size_t) (cursor - list->
start);
71 size_t right = list->
size - 1;
73 while (left <= right) {
74 size_t mid = left + (right - left) / 2;
76 if (list->
offsets[mid] == offset) {
80 if (list->
offsets[mid] < offset) {
A list of byte offsets of newlines in a string.
A line and column in a string.
A list of offsets of newlines in a string.
const uint8_t * start
A pointer to the start of the source string.
size_t capacity
The capacity of the list that has been allocated.
size_t * offsets
The list of offsets.
size_t size
The number of offsets in the list.