55 lines
1.3 KiB
C++
55 lines
1.3 KiB
C++
#include "PieceTable.h"
|
|
|
|
PieceTable::PieceTable(const uint8_t * file_buffer, unsigned long file_buffer_size)
|
|
{
|
|
m_file_buffer = file_buffer;
|
|
m_file_buffer_size = file_buffer_size;
|
|
start_piece = &m_pieces[PIECE_INDEX_START];
|
|
end_piece = &m_pieces[PIECE_INDEX_END];
|
|
start_piece->next = end_piece;
|
|
end_piece->prev = start_piece;
|
|
m_piece_index = 2u;
|
|
}
|
|
|
|
void PieceTable::append_initial_line_piece(uint8_t * start, uint32_t length, bool eol)
|
|
{
|
|
Piece * piece = add_piece();
|
|
piece->prev = end_piece->prev;
|
|
piece->next = end_piece;
|
|
piece->start = start;
|
|
piece->length = length;
|
|
piece->flags = 0u;
|
|
if (eol)
|
|
piece->flags |= Piece::EOL_FLAG;
|
|
end_piece->prev->next = piece;
|
|
end_piece->prev = piece;
|
|
m_num_lines++;
|
|
}
|
|
|
|
PieceTable::Piece * PieceTable::get_start_of_line(PieceTable::Piece * start) const
|
|
{
|
|
Piece * piece = start;
|
|
|
|
while (piece->prev != start_piece && !piece->prev->eol())
|
|
{
|
|
piece = piece->prev;
|
|
}
|
|
|
|
return piece;
|
|
}
|
|
|
|
std::shared_ptr<PieceTable::Cursor> PieceTable::add_cursor()
|
|
{
|
|
auto cursor = std::make_shared<Cursor>();
|
|
|
|
cursor->piece_table = this;
|
|
cursor->piece = start_piece->next;
|
|
cursor->line_number = 0u;
|
|
cursor->offset = 0u;
|
|
cursor->column = 0u;
|
|
|
|
m_cursors.push_back(cursor);
|
|
|
|
return cursor;
|
|
}
|