diff options
Diffstat (limited to 'src/archive.cpp')
-rw-r--r-- | src/archive.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/archive.cpp b/src/archive.cpp index 93b3773..6c0d3ed 100644 --- a/src/archive.cpp +++ b/src/archive.cpp @@ -5,11 +5,11 @@ namespace bookmouse { -ZipArchive::ZipArchive(const std::string& filename) +ZipArchive::ZipArchive(const fud::String& filename) { // qDebug("Open file %s", filename.data()); int err; - m_archive = zip_open(filename.data(), 0, &err); + m_archive = zip_open(filename.c_str(), 0, &err); if (m_archive == nullptr) { zip_error_t error; zip_error_init_with_code(&error, err); @@ -31,9 +31,18 @@ void ZipArchive::populate() // qDebug("%zu pages", numEntries); struct NameIndex { - std::string name; + fud::String name; size_t index; size_t filesize; + + static bool compare(const NameIndex& lhs, const NameIndex& rhs) + { + return std::lexicographical_compare( // force break + lhs.name.begin(), + lhs.name.end(), + rhs.name.begin(), + rhs.name.end()); + } }; std::vector<NameIndex> nameIndices{}; @@ -58,7 +67,7 @@ void ZipArchive::populate() // qWarning("cannot get name %s", zip_error_strerror(error)); continue; } - std::string name{nameCString}; + fud::String name{nameCString}; if (name.empty() || name.back() == '/') { // qDebug("Directory %s", name.empty() ? "N/A" : nameCString); continue; @@ -69,7 +78,7 @@ void ZipArchive::populate() } std::sort(nameIndices.begin(), nameIndices.end(), [](const auto& lhs, const auto& rhs) { - return std::lexicographical_compare(lhs.name.begin(), lhs.name.end(), rhs.name.begin(), rhs.name.end()); + return NameIndex::compare(lhs, rhs); }); m_sortedIndices.reserve(nameIndices.size()); @@ -91,12 +100,9 @@ ZipArchive::~ZipArchive() } } -ZipArchive::ZipArchive(ZipArchive&& rhs) - : m_archive{rhs.m_archive}, - m_sortedIndices{std::move(rhs.m_sortedIndices)}, - m_filenames{std::move(rhs.m_filenames)}, - m_fileSizes{std::move(rhs.m_fileSizes)}, - m_pages{std::move(rhs.m_pages)} +ZipArchive::ZipArchive(ZipArchive&& rhs) : + m_archive{rhs.m_archive}, m_sortedIndices{std::move(rhs.m_sortedIndices)}, m_filenames{std::move(rhs.m_filenames)}, + m_fileSizes{std::move(rhs.m_fileSizes)}, m_pages{std::move(rhs.m_pages)} { rhs.m_archive = nullptr; } @@ -161,7 +167,8 @@ ArchiveResult ZipArchive::getPage(size_t page) return ArchiveResult::okay(std::cref(*m_pages[page])); } -size_t ZipArchive::numPages() const { +size_t ZipArchive::numPages() const +{ return m_pages.size(); } |