From b478d17e16064f66f3bf246e5f6170cc84b5d991 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sat, 27 Aug 2016 15:43:35 -0400 Subject: [PATCH] add Interator and Cursor constructors --- src/core/PieceTable.cc | 13 ++++++++----- src/core/PieceTable.h | 4 ++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/core/PieceTable.cc b/src/core/PieceTable.cc index cf74667..74f7140 100644 --- a/src/core/PieceTable.cc +++ b/src/core/PieceTable.cc @@ -29,17 +29,20 @@ void PieceTable::append_initial_line_piece(uint8_t * start, uint32_t length, boo std::shared_ptr PieceTable::add_cursor() { - auto cursor = std::make_shared(); - - cursor->iterator.piece_table = this; - cursor->iterator.piece = start_piece->next; - cursor->iterator.offset = 0u; + auto cursor = std::make_shared(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) diff --git a/src/core/PieceTable.h b/src/core/PieceTable.h index b877b38..64e864f 100644 --- a/src/core/PieceTable.h +++ b/src/core/PieceTable.h @@ -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);