/* ***************************************************************************** * This file is part of the Quest Text Editor project. * Copyright (c) 2021 Daniel Swanson (@mr-martian), Dusty Miller (@d-us-vb), * killerbee (@killerbee13), Richard (@CodeTriangle) * * This file contains the implementation and tests for utf8_rope * * ****************************************************************************/ #include "utf8_rope.hpp" #include namespace quest { utf8_rope::utf8_rope(std::string_view str) {} utf8_rope::utf8_rope(std::u8string_view str) : utf8_rope(std::string_view(reinterpret_cast(str.data()), str.size())) {} utf8_rope::utf8_rope(std::initializer_list il) {} utf8_rope::utf8_rope(std::initializer_list il) {} void utf8_rope::assign(std::initializer_list il) {} void utf8_rope::assign(std::initializer_list il) {} void utf8_rope::assign(std::string_view str) {} void utf8_rope::assign(std::u8string_view str) {} void utf8_rope::assign(utf8_rope::size_type num, char8_t val) {} utf8_rope::iterator utf8_rope::begin() noexcept {} utf8_rope::const_iterator utf8_rope::begin() const noexcept {} utf8_rope::const_iterator utf8_rope::cbegin() const noexcept {} utf8_rope::iterator utf8_rope::end() noexcept {} utf8_rope::const_iterator utf8_rope::end() const noexcept {} utf8_rope::const_iterator utf8_rope::cend() const noexcept {} utf8_rope::reverse_iterator utf8_rope::rbegin() noexcept {} utf8_rope::const_reverse_iterator utf8_rope::rbegin() const noexcept {} utf8_rope::const_reverse_iterator utf8_rope::crbegin() const noexcept {} utf8_rope::reverse_iterator utf8_rope::rend() noexcept {} utf8_rope::const_reverse_iterator utf8_rope::rend() const noexcept {} utf8_rope::const_reverse_iterator utf8_rope::crend() const noexcept {} void utf8_rope::swap(utf8_rope& other) noexcept { std::swap(tree, other.tree); } bool utf8_rope::empty() const noexcept { return tree->empty(); } utf8_rope::iterator utf8_rope::insert(utf8_rope::const_iterator pos, char8_t val) {} utf8_rope::iterator utf8_rope::insert(utf8_rope::const_iterator pos, char val) { } utf8_rope::iterator utf8_rope::insert(utf8_rope::const_iterator pos, utf8_rope::size_type num, char8_t val) {} utf8_rope::iterator utf8_rope::insert(utf8_rope::const_iterator pos, utf8_rope::size_type num, char val) {} utf8_rope::iterator utf8_rope::insert(utf8_rope::const_iterator pos, std::initializer_list il) {} utf8_rope::iterator utf8_rope::insert(utf8_rope::const_iterator pos, std::initializer_list il) {} utf8_rope::iterator utf8_rope::erase(utf8_rope::const_iterator pos) {} utf8_rope::iterator utf8_rope::erase(utf8_rope::const_iterator begin, utf8_rope::const_iterator end) {} void utf8_rope::clear() noexcept { tree.reset(); } utf8_rope::reference utf8_rope::front() {} utf8_rope::const_reference utf8_rope::front() const {} utf8_rope::reference utf8_rope::back() {} utf8_rope::const_reference utf8_rope::back() const {} void utf8_rope::push_front(char8_t val) {} void utf8_rope::push_back(char8_t val) {} void utf8_rope::pop_front() noexcept {} void utf8_rope::pop_back() noexcept {} // utf8_rope::reference utf8_rope::at(utf8_rope::size_type idx) {} // utf8_rope::const_reference utf8_rope::at(utf8_rope::size_type idx) const {} // utf8_rope::iterator utf8_rope::nth(utf8_rope::size_type idx) noexcept {} // utf8_rope::const_iterator utf8_rope::nth( // utf8_rope::size_type idx) const noexcept {} // utf8_rope::size_type utf8_rope::index_of( // utf8_rope::const_iterator it) const noexcept {} utf8_rope::sizes utf8_rope::find_last_cluster_within(std::string_view str) { return {str.size(), str.size(), str.size(), str.size(), str.size()}; } std::shared_ptr utf8_rope::node::allocate_subtree( const std::string_view contents, std::size_t capacity) { capacity = std::max(capacity, contents.size()); if (capacity > max_size_) { throw std::length_error("rope: requested size greater than max_size()"); } else { // divide string into approximately equal segments auto remaining_length = capacity; auto remaining_contents = contents; struct fragment_t { std::shared_ptr tree{}; sizes cumulative{}; }; std::deque queue; while (remaining_length) { auto partition = find_last_cluster_within( remaining_contents.substr(0, target_fragment_length)); auto& fragment = queue.emplace_back( fragment_t{std::make_shared(node::leaf)}); auto& node_ = *fragment.tree; std::get(node_.data) .assign(remaining_contents.substr(0, partition.chars)); node_.assign_from(partition); fragment.cumulative += partition; remaining_contents.remove_prefix(partition.chars); remaining_length -= partition.chars; } // build tree out of segments std::abort(); } } } // namespace quest