diff --git a/src/book.cpp b/src/book.cpp index 6bf90cc..8a55ec5 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -23,6 +23,8 @@ #include +#include +#include #include #include #include @@ -57,8 +59,9 @@ book read(const fs::path filepath, const bool raw) else { doc.text_raw = zip::read_file(filepath, entry); + doc.text = std::make_unique(doc.text_raw); } - current_book.files.emplace_back(entry, doc); + current_book.files.emplace_back(entry, std::move(doc)); } return current_book; @@ -143,6 +146,7 @@ document process_page(const std::string_view text) } doc.text_cleaned = output; + doc.text = std::make_unique(doc.text_cleaned); return doc; } diff --git a/src/book.hpp b/src/book.hpp index 70bfbd5..16071ae 100644 --- a/src/book.hpp +++ b/src/book.hpp @@ -20,6 +20,7 @@ #include "fs-compat.hpp" #include +#include #include #include #include @@ -35,6 +36,7 @@ struct document { string text_raw; //!< HTML page string text_cleaned; //!< Plain text page + std::unique_ptr text; //!< Pointer to preferred text version std::map headlines; //!< pos, title std::map pages; //!< pos, page string language; //!< Page language diff --git a/src/search.cpp b/src/search.cpp index e89b2e7..b596bef 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -78,16 +78,8 @@ std::vector search(const fs::path &filepath, for (const auto &file : book.files) { const auto &doc{file.second}; - const auto &text{[&doc, &opts] - { - if (!opts.raw) - { - return doc.text_cleaned; - } - return doc.text_raw; - }()}; - string::const_iterator begin{text.begin()}; - string::const_iterator end{text.end()}; + string::const_iterator begin{doc.text->begin()}; + string::const_iterator end{doc.text->end()}; auto begin_text{begin}; boost::match_results match_result;