Major updates/cleanup.
This commit is contained in:
@@ -74,14 +74,7 @@ void _insert(AppendStorage *ap, Shard **root, Point *point, const char *data, ui
|
||||
++lines;
|
||||
last_line = ++data;
|
||||
}
|
||||
uint64_t col = 0;
|
||||
uint64_t remaining = end - last_line;
|
||||
while (remaining) {
|
||||
uint64_t n = grapheme_next_character_break_utf8(last_line, remaining);
|
||||
last_line += n;
|
||||
remaining -= n;
|
||||
++col;
|
||||
}
|
||||
uint64_t col = end - last_line;
|
||||
if (lines) {
|
||||
point->row += lines;
|
||||
point->col = col;
|
||||
@@ -122,6 +115,22 @@ Shard *replace(AppendStorage *ap, Shard *root, Range range, const char *data, ui
|
||||
return insert(ap, root, &range.start, data, len);
|
||||
}
|
||||
|
||||
Point eof_point(Shard *root) {
|
||||
if (!root)
|
||||
return {0, 0};
|
||||
Point result{
|
||||
.row = root->lines,
|
||||
.col = 0
|
||||
};
|
||||
PetalIterator it(root, Direction::Forward);
|
||||
it.seek_line(root->lines);
|
||||
const char *data;
|
||||
uint64_t len;
|
||||
while (it.next(&data, &len))
|
||||
result.col += len;
|
||||
return result;
|
||||
}
|
||||
|
||||
uint64_t offset_of(Shard *root, Point point) {
|
||||
return offset_of(root, point.row) + point.col;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user