add Interator and Cursor constructors

This commit is contained in:
Josh Holtrop 2016-08-27 15:43:35 -04:00
parent d6b3810a3c
commit b478d17e16
2 changed files with 12 additions and 5 deletions

View File

@ -29,17 +29,20 @@ void PieceTable::append_initial_line_piece(uint8_t * start, uint32_t length, boo
std::shared_ptr<PieceTable::Cursor> PieceTable::add_cursor()
{
auto cursor = std::make_shared<Cursor>();
cursor->iterator.piece_table = this;
cursor->iterator.piece = start_piece->next;
cursor->iterator.offset = 0u;
auto cursor = std::make_shared<Cursor>(this);
m_cursors.push_back(cursor);
return cursor;
}
PieceTable::Iterator::Iterator(PieceTable * pt)
{
piece_table = pt;
piece = pt->start_piece->next;
offset = 0u;
}
uint8_t PieceTable::Iterator::num_bytes_in_code_point() const
{
if (offset >= piece->length)

View File

@ -59,6 +59,8 @@ public:
/** Byte offset within the piece. */
uint32_t offset;
Iterator(PieceTable * pt);
/** Get the character pointed to by the cursor. */
uint32_t operator*() const
{
@ -102,6 +104,8 @@ public:
return *iterator;
}
Cursor(PieceTable * pt) : iterator(pt) {}
void go_start_of_line();
void go_end_of_line();
bool go_up(int n = 1);