From 5b9daf0d9d656e84c13b415fbea9347b4fa79900 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Mon, 4 Mar 2024 17:30:13 +0400 Subject: [PATCH] Extracted HumanReadableNameMapper::mapName() No cleanup of the new function was performed to keep the diff minimal. --- include/name_mapper.h | 3 +++ src/name_mapper.cpp | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/name_mapper.h b/include/name_mapper.h index 63333515d..28706350e 100644 --- a/include/name_mapper.h +++ b/include/name_mapper.h @@ -54,6 +54,9 @@ class HumanReadableNameMapper : public NameMapper { virtual ~HumanReadableNameMapper() = default; virtual std::string getNameForId(const std::string& id) const; virtual std::string getIdForName(const std::string& name) const; + + private: + void mapName(const kiwix::Library& lib, std::string name, std::string id); }; class UpdatableNameMapper : public NameMapper { diff --git a/src/name_mapper.cpp b/src/name_mapper.cpp index bf2a2e4dd..56844cc04 100644 --- a/src/name_mapper.cpp +++ b/src/name_mapper.cpp @@ -38,9 +38,16 @@ HumanReadableNameMapper::HumanReadableNameMapper(kiwix::Library& library, bool w if (aliasName == bookName) { continue; } + + mapName(library, aliasName, bookId); + } +} + +void HumanReadableNameMapper::mapName(const Library& library, std::string aliasName, std::string bookId) { if (m_nameToId.find(aliasName) == m_nameToId.end()) { m_nameToId[aliasName] = bookId; } else { + const auto& currentBook = library.getBookById(bookId); auto alreadyPresentPath = library.getBookById(m_nameToId[aliasName]).getPath(); std::cerr << "Path collision: " << alreadyPresentPath << " and " << currentBook.getPath() @@ -48,7 +55,6 @@ HumanReadableNameMapper::HumanReadableNameMapper(kiwix::Library& library, bool w << " Therefore, only " << alreadyPresentPath << " will be served." << std::endl; } - } } std::string HumanReadableNameMapper::getNameForId(const std::string& id) const {