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:
parent
a7c838036d
commit
999db2ed78
@ -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));
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user