From 81dd6b162351d93dae5d71a45df56ee1a74a36ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Tue, 7 Jul 2020 13:04:26 -0300 Subject: Split application into server and client --- point.cpp | 95 +++++++++++++++++++-------------------------------------------- 1 file changed, 28 insertions(+), 67 deletions(-) (limited to 'point.cpp') diff --git a/point.cpp b/point.cpp index a331cb7..b0be8e9 100644 --- a/point.cpp +++ b/point.cpp @@ -2,26 +2,6 @@ #include #include -size_t byte_type(uint8_t byte) { - if (byte & 1 << 7) { - if (byte & 1 << 6) { - if (byte & 1 << 5) { - if (byte & 1 << 4) { - return 4; - } else { - return 3; - } - } else { - return 2; - } - } else { - return 0; - } - } else { - return 1; - } -} - struct Point { Page *page; uint16_t index; @@ -76,32 +56,12 @@ struct Point { } } - void pop_byte() { - if (!at_start()) { - align_gap(); - page->pop(); - move_backward(); - if (index == 0) { - move_backward(); - } - } - if (page->is_empty()) { - if (page->prev) { - move_backward(); - delete page->next; - } else if (page->next) { - page->next->copy_to(page); - delete page->next; - index = 0; - } - } - } public: - Point() : page(new Page()), index(0) {} - Point(Page *page, uint16_t index) : page(page), index(index) {} - Point(const Point& p) : page(p.page), index(p.index) {} + Point() : page(0), index(0) {} + Point(Page* page, uint16_t index) : page(page), index(index) {} + Point(const Point &p) : page(p.page), index(p.index) {} bool operator==(Point p) { return page == p.page && index == p.index; @@ -120,30 +80,17 @@ struct Point { } void operator++(int) { - do { - if (index == page->element_count) move_forward(); - move_forward(); - } while (!byte_type(next_byte())); + if (index == page->element_count) move_forward(); + move_forward(); } void operator--(int) { - do { - move_backward(); - if (index == 0) move_backward(); - } while (!byte_type(next_byte())); - } - - wchar_t element() { - size_t type = byte_type(next_byte()); - wchar_t rune = next_byte() & (0xff >> type); - Point iter(*this); - for (size_t i = 1; i < type; i++) { - rune <<= 6; - iter.move_forward(); - if (iter.index == 0) iter.move_forward(); - rune |= (iter.next_byte() & 0x3f); - } - return rune; + move_backward(); + if (index == 0) move_backward(); + } + + char element() { + return next_byte(); } uint64_t seek(uint8_t c, uint64_t limit) { @@ -187,10 +134,24 @@ struct Point { } void pop() { - while (!byte_type(prev_byte())) { - pop_byte(); + if (!at_start()) { + align_gap(); + page->pop(); + move_backward(); + if (index == 0) { + move_backward(); + } + } + if (page->is_empty()) { + if (page->prev) { + move_backward(); + delete page->next; + } else if (page->next) { + page->next->copy_to(page); + delete page->next; + index = 0; + } } - pop_byte(); } }; -- cgit v1.2.3