Преглед изворни кода

Replaced legacy sprintf with boost::format.

DjWarmonger пре 11 година
родитељ
комит
c094e70784

+ 2 - 4
client/CPlayerInterface.cpp

@@ -677,10 +677,8 @@ void CPlayerInterface::battleStacksHealedRes(const std::vector<std::pair<ui32, u
 			CCS->soundh->playSound(soundBase::DRAINLIF);
 
 			//print info about life drain
-			char textBuf[1000];
-			snprintf(textBuf, 1000, CGI->generaltexth->allTexts[361 + textOff].c_str(), attacker->getCreature()->nameSing.c_str(),
-				healedStacks[0].second, defender->getCreature()->namePl.c_str());
-			battleInt->console->addText(textBuf);
+			auto txt =  boost::format (CGI->generaltexth->allTexts[361 + textOff]) %  attacker->getCreature()->nameSing % healedStacks[0].second % defender->getCreature()->namePl;
+			battleInt->console->addText(boost::to_string(txt));
 		}
 	}
 	if (tentHeal)

+ 10 - 14
client/battle/CBattleInterface.cpp

@@ -831,11 +831,10 @@ void CBattleInterface::bFleef()
 			if(defendingHeroInstance->tempOwner == curInt->cb->getMyColor())
 				heroName = defendingHeroInstance->name;
 		//calculating text
-		char buffer[1000];
-		snprintf(buffer, 1000, CGI->generaltexth->allTexts[340].c_str(), heroName.c_str()); //The Shackles of War are present.  %s can not retreat!
+		auto txt = boost::format(CGI->generaltexth->allTexts[340]) % heroName; //The Shackles of War are present.  %s can not retreat!
 
 		//printing message
-		curInt->showInfoDialog(std::string(buffer), comps);
+		curInt->showInfoDialog(boost::to_string(txt), comps);
 	}
 }
 
@@ -1519,12 +1518,11 @@ void CBattleInterface::battleStacksEffectsSet(const SetStackEffect & sse)
 			if(stack->count != 1)
 				txtid++; //move to plural text
 
-			char txt[4000];
 			BonusList defenseBonuses = *(stack->getBonuses(Selector::typeSubtype(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE)));
 			defenseBonuses.remove_if(Selector::durationType(Bonus::STACK_GETS_TURN)); //remove bonuses gained from defensive stance
 			int val = stack->Defense() - defenseBonuses.totalValue();
-			snprintf(txt, 4000, CGI->generaltexth->allTexts[txtid].c_str(),  (stack->count != 1) ? stack->getCreature()->namePl.c_str() : stack->getCreature()->nameSing.c_str(), val);
-			console->addText(txt);
+			auto txt = boost::format (CGI->generaltexth->allTexts[txtid]) % ((stack->count != 1) ? stack->getCreature()->namePl : stack->getCreature()->nameSing) % val;
+			console->addText(boost::to_string(txt));
 		}
 	}
 
@@ -1793,28 +1791,26 @@ void CBattleInterface::getPossibleActionsForStack(const CStack * stack)
 
 void CBattleInterface::printConsoleAttacked( const CStack * defender, int dmg, int killed, const CStack * attacker, bool multiple )
 {
-	char tabh[200] = {0};
+	boost::format txt;
 	int end = 0;
 	if (attacker) //ignore if stacks were killed by spell
 	{
-		end = snprintf(tabh, 200, CGI->generaltexth->allTexts[attacker->count > 1 ? 377 : 376].c_str(),
-		(attacker->count > 1 ? attacker->getCreature()->namePl.c_str() : attacker->getCreature()->nameSing.c_str()), dmg);
+		txt = boost::format (CGI->generaltexth->allTexts[attacker->count > 1 ? 377 : 376]) %
+			(attacker->count > 1 ? attacker->getCreature()->namePl : attacker->getCreature()->nameSing) % dmg;
 	}
 	if(killed > 0)
 	{
 		if(killed > 1)
 		{
-			snprintf(tabh + end, 400, CGI->generaltexth->allTexts[379].c_str(), killed,
-				multiple ? CGI->generaltexth->allTexts[43].c_str() : defender->getCreature()->namePl.c_str()); // creatures perish
+			txt = boost::format (CGI->generaltexth->allTexts[379]) % killed % (multiple ? CGI->generaltexth->allTexts[43] : defender->getCreature()->namePl); // creatures perish
 		}
 		else //killed == 1
 		{
-			snprintf(tabh + end, 400, CGI->generaltexth->allTexts[378].c_str(),
-				multiple ? CGI->generaltexth->allTexts[42].c_str() : defender->getCreature()->nameSing.c_str()); // creature perishes
+			txt = boost::format (CGI->generaltexth->allTexts[378]) % (multiple ? CGI->generaltexth->allTexts[42] : defender->getCreature()->nameSing); // creature perishes
 		}
 	}
 
-	console->addText(std::string(tabh));
+	console->addText(boost::to_string (txt));
 }
 
 

+ 2 - 3
client/battle/CBattleInterfaceClasses.cpp

@@ -577,10 +577,9 @@ void CClickableHex::mouseMoved(const SDL_MouseMotionEvent &sEvent)
 			attackedStack->owner != myInterface->getCurrentPlayerInterface()->playerID &&
 			attackedStack->alive())
 		{
-			char tabh[160];
 			const std::string & attackedName = attackedStack->count == 1 ? attackedStack->getCreature()->nameSing : attackedStack->getCreature()->namePl;
-			snprintf(tabh, 160, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str());
-			myInterface->console->alterTxt = std::string(tabh);
+			auto txt = boost::format (CGI->generaltexth->allTexts[220]) % attackedName;
+			myInterface->console->alterTxt = boost::to_string(txt);
 			setAlterText = true;
 		}
 	}