1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

small refactoring

This commit is contained in:
Laserlicht
2025-06-22 00:20:03 +02:00
parent de893a3575
commit bd090059da
4 changed files with 19 additions and 29 deletions

View File

@@ -112,19 +112,6 @@ std::shared_ptr<CampaignState> CampaignHandler::getCampaign( const std::string &
return ret; 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) 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); 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) 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()) if (text.empty())
return ""; return "";

View File

@@ -46,25 +46,11 @@
VCMI_LIB_NAMESPACE_BEGIN 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) CMapLoaderH3M::CMapLoaderH3M(const std::string & mapName, const std::string & modName, const std::string & encodingName, CInputStream * stream)
: map(nullptr) : map(nullptr)
, reader(new MapReaderH3M(stream)) , reader(new MapReaderH3M(stream))
, inputStream(stream) , inputStream(stream)
, mapName(convertMapName(mapName)) , mapName(TextOperations::convertMapName(mapName))
, modName(modName) , modName(modName)
, fileEncoding(encodingName) , fileEncoding(encodingName)
{ {

View File

@@ -423,4 +423,18 @@ boost::filesystem::path TextOperations::Utf8TofilesystemPath(const std::string&
#endif #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 VCMI_LIB_NAMESPACE_END

View File

@@ -91,6 +91,9 @@ namespace TextOperations
// Used for handling paths with non-ASCII characters. // Used for handling paths with non-ASCII characters.
DLL_LINKAGE boost::filesystem::path Utf8TofilesystemPath(const std::string& path); 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<typename Arithmetic> template<typename Arithmetic>