add PieceTable::append_initial_line_piece()
This commit is contained in:
parent
8fcbad02f8
commit
e52710b47c
@ -56,14 +56,8 @@ bool Buffer::load_from_file(const char * filename)
|
||||
m_piece_table = std::make_shared<PieceTable>(m_file_buffer, m_file_buffer_size);
|
||||
for (auto it = text_loader.begin(); it != text_loader.end(); it++)
|
||||
{
|
||||
PieceTable::PieceDescriptor * pd = m_piece_table->add_piece_descriptor();
|
||||
pd->prev = m_piece_table->end_descriptor->prev;
|
||||
pd->next = m_piece_table->end_descriptor;
|
||||
pd->start = it->first;
|
||||
pd->length = it->second;
|
||||
pd->n_chars = it->second | PIECE_DESCRIPTOR_N_CHARS_EOL_FLAG_MASK; /* TODO: fix this for other encodings */
|
||||
m_piece_table->end_descriptor->prev->next = pd;
|
||||
m_piece_table->end_descriptor->prev = pd;
|
||||
/* TODO: correctly calculate n_chars based on current file encoding. */
|
||||
m_piece_table->append_initial_line_piece(it->first, it->second, it->second);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -10,3 +10,16 @@ PieceTable::PieceTable(const uint8_t * file_buffer, unsigned long file_buffer_si
|
||||
end_descriptor->prev = start_descriptor;
|
||||
m_piece_descriptor_index = 2u;
|
||||
}
|
||||
|
||||
void PieceTable::append_initial_line_piece(uint8_t * start, uint32_t length, uint32_t n_chars)
|
||||
{
|
||||
PieceDescriptor * pd = add_piece_descriptor();
|
||||
pd->prev = end_descriptor->prev;
|
||||
pd->next = end_descriptor;
|
||||
pd->start = start;
|
||||
pd->length = length;
|
||||
pd->n_chars = n_chars | PIECE_DESCRIPTOR_N_CHARS_EOL_FLAG_MASK;
|
||||
end_descriptor->prev->next = pd;
|
||||
end_descriptor->prev = pd;
|
||||
m_num_lines++;
|
||||
}
|
||||
|
@ -63,12 +63,17 @@ public:
|
||||
return m_piece_descriptors[index];
|
||||
}
|
||||
|
||||
uint32_t get_num_lines() { return m_num_lines; }
|
||||
|
||||
PieceDescriptor * start_descriptor;
|
||||
PieceDescriptor * end_descriptor;
|
||||
|
||||
void append_initial_line_piece(uint8_t * start, uint32_t length, uint32_t n_chars);
|
||||
|
||||
protected:
|
||||
const uint8_t * m_file_buffer;
|
||||
unsigned long m_file_buffer_size;
|
||||
uint32_t m_num_lines;
|
||||
|
||||
/** Next available piece descriptor index. */
|
||||
uint32_t m_piece_descriptor_index;
|
||||
|
Loading…
x
Reference in New Issue
Block a user