10 if (list->
offsets == NULL)
return false;
37 size_t *original_offsets = list->
offsets;
41 if (list->
offsets == NULL)
return false;
43 memcpy(list->
offsets, original_offsets, list->
size *
sizeof(
size_t));
44 xfree(original_offsets);
47 assert(*cursor ==
'\n');
48 assert(cursor >= list->
start);
49 size_t newline_offset = (size_t) (cursor - list->
start + 1);
51 assert(list->
size == 0 || newline_offset > list->
offsets[list->
size - 1]);
63 assert(cursor >= list->
start);
64 size_t offset = (size_t) (cursor - list->
start);
67 size_t right = list->
size - 1;
69 while (left <= right) {
70 size_t mid = left + (right - left) / 2;
72 if (list->
offsets[mid] == offset) {
73 return ((int32_t) mid) + start_line;
76 if (list->
offsets[mid] < offset) {
83 return ((int32_t) left) + start_line - 1;
93 assert(cursor >= list->
start);
94 size_t offset = (size_t) (cursor - list->
start);
97 size_t right = list->
size - 1;
99 while (left <= right) {
100 size_t mid = left + (right - left) / 2;
102 if (list->
offsets[mid] == offset) {
106 if (list->
offsets[mid] < offset) {
114 .line = ((int32_t) left) + start_line - 1,
115 .column = (uint32_t) (offset - list->
offsets[left - 1])
#define xfree
Old name of ruby_xfree.
#define xcalloc
Old name of ruby_xcalloc.
A list of byte offsets of newlines in a string.
pm_line_column_t pm_newline_list_line_column(const pm_newline_list_t *list, const uint8_t *cursor, int32_t start_line)
Returns the line and column of the given offset.
void pm_newline_list_free(pm_newline_list_t *list)
Free the internal memory allocated for the newline list.
int32_t pm_newline_list_line(const pm_newline_list_t *list, const uint8_t *cursor, int32_t start_line)
Returns the line of the given offset.
bool pm_newline_list_init(pm_newline_list_t *list, const uint8_t *start, size_t capacity)
Initialize a new newline list with the given capacity.
bool pm_newline_list_append(pm_newline_list_t *list, const uint8_t *cursor)
Append a new offset to the newline list.
void pm_newline_list_clear(pm_newline_list_t *list)
Clear out the newlines that have been appended to the list.
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.