Major fixes:

- ChunkIterator is now bidirectional
- LineIterator is now also bidirectional
- Undo/redo history operations
- Replace operation
- Range based api functions
- And more minor bug fixes
This commit is contained in:
2026-08-03 20:26:02 +01:00
parent 557edb5191
commit 8c61f186cf
18 changed files with 443 additions and 188 deletions
+16 -15
View File
@@ -1,7 +1,8 @@
#include "vase/buffer/append.h"
AppendBuffer::AppendBuffer() {
new_text_chunk();
t_current = (TChunk *)malloc(sizeof(TChunk));
buf.push_back(t_current);
}
AppendBuffer::~AppendBuffer() {
@@ -10,8 +11,11 @@ AppendBuffer::~AppendBuffer() {
}
uint32_t AppendBuffer::key(char c) {
if (t_offset == CHUNK_SIZE)
new_text_chunk();
if (t_offset == APPEND_CHUNK_SIZE) {
t_current = (TChunk *)malloc(sizeof(TChunk));
buf.push_back(t_current);
t_offset = 0;
}
(*t_current)[t_offset++] = c;
return current_offset++;
}
@@ -19,9 +23,12 @@ uint32_t AppendBuffer::key(char c) {
uint32_t AppendBuffer::append(const char *text, uint32_t length) {
uint32_t start = current_offset;
while (length > 0) {
if (t_offset == CHUNK_SIZE)
new_text_chunk();
uint32_t copy = std::min(length, CHUNK_SIZE - t_offset);
if (t_offset == APPEND_CHUNK_SIZE) {
t_current = (TChunk *)malloc(sizeof(TChunk));
buf.push_back(t_current);
t_offset = 0;
}
uint32_t copy = std::min(length, APPEND_CHUNK_SIZE - t_offset);
memcpy((*t_current) + t_offset, text, copy);
t_offset += copy;
current_offset += copy;
@@ -34,21 +41,15 @@ uint32_t AppendBuffer::append(const char *text, uint32_t length) {
const char *AppendBuffer::read(uint32_t pos, uint32_t *out_len) {
if (pos >= current_offset)
return nullptr;
uint32_t local_offset = pos % CHUNK_SIZE;
uint32_t local_offset = pos % APPEND_CHUNK_SIZE;
if (out_len) {
uint32_t remaining = current_offset - pos;
uint32_t until_chunk_end = CHUNK_SIZE - local_offset;
uint32_t until_chunk_end = APPEND_CHUNK_SIZE - local_offset;
*out_len = std::min(remaining, until_chunk_end);
}
return &(*buf[pos / CHUNK_SIZE])[local_offset];
return &(*buf[pos / APPEND_CHUNK_SIZE])[local_offset];
}
inline uint32_t AppendBuffer::length() {
return current_offset;
}
inline void AppendBuffer::new_text_chunk() {
t_current = (TChunk *)malloc(sizeof(TChunk));
buf.push_back(t_current);
t_offset = 0;
}