diff --git a/lib/campaign/CampaignHandler.cpp b/lib/campaign/CampaignHandler.cpp index 4972d0468..53738c985 100644 --- a/lib/campaign/CampaignHandler.cpp +++ b/lib/campaign/CampaignHandler.cpp @@ -112,19 +112,6 @@ std::shared_ptr CampaignHandler::getCampaign( const std::string & return ret; } -static std::string convertMapName(std::string input) -{ - boost::algorithm::to_lower(input); - boost::algorithm::trim(input); - - size_t slashPos = input.find_last_of("/"); - - if (slashPos != std::string::npos) - return input.substr(slashPos + 1); - - return input; -} - std::string CampaignHandler::readLocalizedString(CampaignHeader & target, CBinaryReader & reader, const std::string & filename, const std::string & modName, const std::string & encoding, const std::string & identifier) { const std::string & input = TextOperations::toUnicode(reader.readBaseString(), encoding); @@ -134,7 +121,7 @@ std::string CampaignHandler::readLocalizedString(CampaignHeader & target, CBinar std::string CampaignHandler::readLocalizedString(CampaignHeader & target, const std::string & text, const std::string & filename, const std::string & modName, const std::string & identifier) { - TextIdentifier stringID( "campaign", convertMapName(filename), identifier); + TextIdentifier stringID( "campaign", TextOperations::convertMapName(filename), identifier); if (text.empty()) return ""; diff --git a/lib/mapping/MapFormatH3M.cpp b/lib/mapping/MapFormatH3M.cpp index 8afa96e57..a8c0e60f6 100644 --- a/lib/mapping/MapFormatH3M.cpp +++ b/lib/mapping/MapFormatH3M.cpp @@ -46,25 +46,11 @@ VCMI_LIB_NAMESPACE_BEGIN -static std::string convertMapName(std::string input) -{ - boost::algorithm::to_lower(input); - boost::algorithm::trim(input); - boost::algorithm::erase_all(input, "."); - - size_t slashPos = input.find_last_of('/'); - - if(slashPos != std::string::npos) - return input.substr(slashPos + 1); - - return input; -} - CMapLoaderH3M::CMapLoaderH3M(const std::string & mapName, const std::string & modName, const std::string & encodingName, CInputStream * stream) : map(nullptr) , reader(new MapReaderH3M(stream)) , inputStream(stream) - , mapName(convertMapName(mapName)) + , mapName(TextOperations::convertMapName(mapName)) , modName(modName) , fileEncoding(encodingName) { diff --git a/lib/texts/TextOperations.cpp b/lib/texts/TextOperations.cpp index 0346dfe65..3a83e42ec 100644 --- a/lib/texts/TextOperations.cpp +++ b/lib/texts/TextOperations.cpp @@ -423,4 +423,18 @@ boost::filesystem::path TextOperations::Utf8TofilesystemPath(const std::string& #endif } +std::string TextOperations::convertMapName(std::string input) +{ + boost::algorithm::to_lower(input); + boost::algorithm::trim(input); + boost::algorithm::erase_all(input, "."); + + size_t slashPos = input.find_last_of('/'); + + if(slashPos != std::string::npos) + return input.substr(slashPos + 1); + + return input; +} + VCMI_LIB_NAMESPACE_END diff --git a/lib/texts/TextOperations.h b/lib/texts/TextOperations.h index 63933ae56..bae9c5873 100644 --- a/lib/texts/TextOperations.h +++ b/lib/texts/TextOperations.h @@ -91,6 +91,9 @@ namespace TextOperations // Used for handling paths with non-ASCII characters. DLL_LINKAGE boost::filesystem::path Utf8TofilesystemPath(const std::string& path); + + /// Strip out unwanted characters from map name + DLL_LINKAGE std::string convertMapName(std::string input); }; template