1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-17 20:58:07 +02:00

Avoid boost::format that throws exception on invalid format string

This commit is contained in:
Ivan Savenko 2023-12-10 16:33:22 +02:00
parent a7c838036d
commit 999db2ed78
2 changed files with 15 additions and 3 deletions

View File

@ -168,7 +168,10 @@ DLL_LINKAGE std::string MetaString::toString() const
boost::replace_first(dst, "%d", std::to_string(numbers[nums++]));
break;
case EMessage::REPLACE_POSITIVE_NUMBER:
boost::replace_first(dst, "%+d", '+' + std::to_string(numbers[nums++]));
if (dst.find("%+d") != std::string::npos)
boost::replace_first(dst, "%+d", '+' + std::to_string(numbers[nums++]));
else
boost::replace_first(dst, "%d", std::to_string(numbers[nums++]));
break;
default:
logGlobal->error("MetaString processing error! Received message of type %d", static_cast<int>(elem));

View File

@ -1224,12 +1224,21 @@ TerrainId CGTownInstance::getNativeTerrain() const
GrowthInfo::Entry::Entry(const std::string &format, int _count)
: count(_count)
{
description = boost::str(boost::format(format) % count);
MetaString formatter;
formatter.appendRawString(format);
formatter.replacePositiveNumber(count);
description = formatter.toString();
}
GrowthInfo::Entry::Entry(int subID, const BuildingID & building, int _count): count(_count)
{
description = boost::str(boost::format("%s %+d") % (*VLC->townh)[subID]->town->buildings.at(building)->getNameTranslated() % count);
MetaString formatter;
formatter.appendRawString("%s %+d");
formatter.replaceRawString((*VLC->townh)[subID]->town->buildings.at(building)->getNameTranslated());
formatter.replacePositiveNumber(count);
description = formatter.toString();
}
GrowthInfo::Entry::Entry(int _count, std::string fullDescription):