Replace more strcmp with std::string::compare or std::string::operator==.

This commit also enables TinyXML STL support.
This commit is contained in:
Tobias Loose
2013-11-23 11:10:41 +01:00
parent 5d0d130587
commit 9d5a83d588
13 changed files with 63 additions and 59 deletions

View File

@@ -1145,7 +1145,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
}
if(strncmp(s.c_str(), "chooseacolor ", strlen("chooseacolor ")) == 0 || strncmp(s.c_str(), "chooseatype ", strlen("chooseatype ")) == 0)
if(s.compare(0, strlen("chooseacolor "), "chooseacolor ") == 0 || s.compare(0, strlen("chooseatype "), "chooseatype ") == 0)
{
MTGAbility * choose = parseChooseActionAbility(s,card,spell,target,0,id);
choose = NEW GenericActivatedAbility(observer, "","",id, card,choose,NULL);

View File

@@ -52,28 +52,28 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
return 0;
s[i] = '\0';
const char* key = s.c_str();
const char* val = key+i+1;
const string key = s.substr(0, i);
const char* val = s.c_str()+i+1;
switch (key[0])
switch (s[0])
{
case 'a':
if (0 == strcmp("auto", key))
if (key == "auto")
{
if (!primitive) primitive = NEW CardPrimitive();
primitive->addMagicText(val);
}
else if (0 == strncmp("auto", key, 4))
else if (key.compare(0, strlen("auto")-1, "auto") == 0)
{
if (!primitive) primitive = NEW CardPrimitive();
primitive->addMagicText(val, key + 4);
primitive->addMagicText(val, key.substr(4));
}
else if (0 == strcmp("alias", key))
else if (key == "alias")
{
if (!primitive) primitive = NEW CardPrimitive();
primitive->alias = atoi(val);
}
else if (0 == strcmp("abilities", key))
else if (key == "abilities")
{
if (!primitive) primitive = NEW CardPrimitive();
string value = val;
@@ -288,21 +288,21 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
case 't':
if (!primitive) primitive = NEW CardPrimitive();
if (0 == strcmp("target", key))
if (key == "target")
{
string value = val;
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
primitive->spellTargetType = value;
}
else if (0 == strcmp("text", key))
else if (key == "text")
primitive->setText(val);
else if (0 == strcmp("type", key))
else if (key == "type")
{
vector<string> values = split(val, ' ');
for (size_t values_i = 0; values_i < values.size(); ++values_i)
primitive->setType(values[values_i]);
}
else if (0 == strcmp("toughness", key)) primitive->setToughness(atoi(val));
else if (key == "toughness") primitive->setToughness(atoi(val));
break;
default:

View File

@@ -25,23 +25,23 @@ bool ModRules::load(string filename)
TiXmlElement* element = node->ToElement();
if (element != NULL)
{
if (strcmp(element->Value(), "menu") == 0)
if (element->ValueStr() == "menu")
{
menu.parse(element);
}
else if (strcmp(element->Value(), "general") == 0)
else if (element->ValueStr() == "general")
{
general.parse(element);
}
else if (strcmp(element->Value(), "cards") == 0)
else if (element->ValueStr() == "cards")
{
cards.parse(element);
}
else if (strcmp(element->Value(), "game") == 0)
else if (element->ValueStr() == "game")
{
game.parse(element);
}
else if (strcmp(element->Value(), "cardgui") == 0)
else if (element->ValueStr() == "cardgui")
{
cardgui.parse(element);
}

View File

@@ -333,15 +333,15 @@ StoryDuel::StoryDuel(TiXmlElement* root, StoryFlow * mParent) :
if (element)
{
const char* textC = element->GetText();
if (strcmp(element->Value(), "onwin") == 0)
if (element->ValueStr() == "onwin")
{
onWin = textC;
}
else if (strcmp(element->Value(), "onlose") == 0)
else if (element->ValueStr() == "onlose")
{
onLose = textC;
}
else if (strcmp(element->Value(), "bg") == 0)
else if (element->ValueStr() == "bg")
{
string text = textC;
bg = string("campaigns/").append(mParent->folder).append("/").append(text);
@@ -396,10 +396,10 @@ int StoryPage::loadElement(TiXmlElement* element)
if (!element) return 0;
const char* textC = element->GetText();
string text = textC;
if (strcmp(element->Value(), "music") == 0)
if (element->ValueStr() == "music")
{
musicFile = string("campaigns/").append(mParent->folder).append("/").append(text);
if (!fileExists(musicFile.c_str())) musicFile = text;
if (!FileExists(musicFile)) musicFile = text;
return 1;
}
return 0;
@@ -434,15 +434,15 @@ StoryDialog::StoryDialog(TiXmlElement* root, StoryFlow * mParent) :
string sFont = safeAttribute(element, "font");
int font = atoi(sFont.c_str());
if (strcmp(element->Value(), "text") == 0)
if (element->ValueStr() == "text")
{
graphics.push_back(NEW StoryText(text, x, y, align, font));
}
else if (strcmp(element->Value(), "title") == 0)
else if (element->ValueStr() == "title")
{
graphics.push_back(NEW StoryText(text, x, y, "center", Fonts::MENU_FONT));
}
else if (strcmp(element->Value(), "img") == 0)
else if (element->ValueStr() == "img")
{
//special case to force center
if (sX.compare("") == 0)
@@ -452,7 +452,7 @@ StoryDialog::StoryDialog(TiXmlElement* root, StoryFlow * mParent) :
string img = string("campaigns/").append(mParent->folder).append("/").append(text);
graphics.push_back(NEW StoryImage(img, x, y));
}
else if (strcmp(element->Value(), "answer") == 0)
else if (element->ValueStr() == "answer")
{
string id = element->Attribute("goto");
if (!align.size()) align = "center";
@@ -461,7 +461,7 @@ StoryDialog::StoryDialog(TiXmlElement* root, StoryFlow * mParent) :
graphics.push_back(sc);
Add(sc);
}
else if (strcmp(element->Value(), "reward") == 0)
else if (element->ValueStr() == "reward")
{
string type = safeAttribute(element, "type");
string value = safeAttribute(element, "value");
@@ -553,7 +553,7 @@ StoryPage * StoryFlow::loadPage(TiXmlElement* element)
if (!typeNode) return NULL;
StoryPage * result = NULL;
const char* type = typeNode->ToElement()->GetText();
if (strcmp(type, "duel") == 0)
if (string("duel") == type)
{
result = NEW StoryDuel(element, this);
}
@@ -615,7 +615,7 @@ bool StoryFlow::parse(string path)
TiXmlElement* element = node->ToElement();
if (element != NULL)
{
if (strcmp(element->Value(), "page") == 0)
if (element->ValueStr() == "page")
{
string id = element->Attribute("id");

View File

@@ -18,6 +18,7 @@ CONFIG(debug, debug|release):DEFINES += _DEBUG
#DEFINES += QT_CONFIG
#DEFINES += NETWORK_SUPPORT
DEFINES += SDL_CONFIG
DEFINES += TIXML_USE_STL
macx:DEFINES += USE_PHONON
maemo5: {
DEFINES += USE_PHONON

View File

@@ -49,6 +49,8 @@ android:INCLUDEPATH += $$ANDROID_NDK_ROOT/platforms/android-9/arch-arm/usr/inclu
#DEFINES += QT_NO_DEBUG_OUTPUT
DEFINES += NETWORK_SUPPORT
DEFINES += TIXML_USE_STL
windows:INCLUDEPATH += ../../JGE/Dependencies/include
windows{
*-g++* {