diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-02-24 22:59:54 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-02-24 22:59:54 +0300 |
commit | 6ce49efadfadd8eacb048df274979736bb04daf0 (patch) | |
tree | 60d4c2c2a803db003f6fa28e932468e925112580 | |
parent | 466829aef10af6b95d0f443226e8549f4399b567 (diff) | |
download | plus-6ce49efadfadd8eacb048df274979736bb04daf0.tar.gz plus-6ce49efadfadd8eacb048df274979736bb04daf0.tar.bz2 plus-6ce49efadfadd8eacb048df274979736bb04daf0.tar.xz plus-6ce49efadfadd8eacb048df274979736bb04daf0.zip |
Improve string usage in some files.
-rw-r--r-- | src/avatar.cpp | 7 | ||||
-rw-r--r-- | src/being.cpp | 26 | ||||
-rw-r--r-- | src/chatlogger.cpp | 7 | ||||
-rw-r--r-- | src/commands.cpp | 70 | ||||
-rw-r--r-- | src/inputmanager.cpp | 10 | ||||
-rw-r--r-- | src/itemshortcut.cpp | 10 | ||||
-rw-r--r-- | src/main.cpp | 2 | ||||
-rw-r--r-- | src/map.cpp | 27 | ||||
-rw-r--r-- | src/shopitem.cpp | 28 | ||||
-rw-r--r-- | src/soundmanager.cpp | 10 | ||||
-rw-r--r-- | src/statuseffect.cpp | 10 | ||||
-rw-r--r-- | src/textcommand.cpp | 2 | ||||
-rw-r--r-- | src/units.cpp | 17 |
13 files changed, 122 insertions, 104 deletions
diff --git a/src/avatar.cpp b/src/avatar.cpp index 4fffcc9fa..f2e6bc4ba 100644 --- a/src/avatar.cpp +++ b/src/avatar.cpp @@ -52,9 +52,14 @@ Avatar::Avatar(const std::string &name): std::string Avatar::getComplexName() const { if (mName == mOriginalName || mOriginalName.empty()) + { return mName; + } else - return mName + "(" + mOriginalName + ")"; + { + return std::string(mName).append("(").append( + mOriginalName).append(")"); + } } std::string Avatar::getAdditionString() const diff --git a/src/being.cpp b/src/being.cpp index 0f64cace3..5448be58a 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -1604,7 +1604,7 @@ std::string Being::getGenderSignWithSpace() const if (str.empty()) return str; else - return " " + str; + return std::string(" ").append(str); } std::string Being::getGenderSign() const @@ -1620,16 +1620,16 @@ std::string Being::getGenderSign() const if (mShowPlayersStatus && mAdvanced) { if (mShop) - str += "$"; + str.append("$"); if (mAway) { // TRANSLATORS: this away status writed in player nick - str += _("A"); + str.append(_("A")); } else if (mInactive) { // TRANSLATORS: this inactive status writed in player nick - str += _("I"); + str.append(_("I")); } } return str; @@ -1653,17 +1653,17 @@ void Being::showName() if (mType != MONSTER && (mShowGender || mShowLevel)) { - displayName += " "; + displayName.append(" "); if (mShowLevel && getLevel() != 0) - displayName += toString(getLevel()); + displayName.append(toString(getLevel())); - displayName += getGenderSign(); + displayName.append(getGenderSign()); } if (mType == MONSTER) { if (config.getBoolValue("showMonstersTakedDamage")) - displayName += ", " + toString(getDamageTaken()); + displayName.append(", ").append(toString(getDamageTaken())); } gcn::Font *font = nullptr; @@ -1803,7 +1803,8 @@ void Being::setSprite(const unsigned int slot, const int id, color = info.getDyeColorsString(colorId); equipmentSprite = AnimatedSprite::delayedLoad( - paths.getStringValue("sprites") + combineDye(filename, color)); + paths.getStringValue("sprites").append( + combineDye(filename, color))); } if (equipmentSprite) @@ -2637,7 +2638,7 @@ std::string Being::loadComment(const std::string &name, const int type) return ""; } - str += stringToHexPath(name) + "/comment.txt"; + str.append(stringToHexPath(name)).append("/comment.txt"); logger->log("load from: %s", str.c_str()); StringVect lines; @@ -2666,9 +2667,10 @@ void Being::saveComment(const std::string &name, default: return; } - dir += stringToHexPath(name); + dir.append(stringToHexPath(name)); const ResourceManager *const resman = ResourceManager::getInstance(); - resman->saveTextFile(dir, "comment.txt", name + "\n" + comment); + resman->saveTextFile(dir, "comment.txt", + (name + "\n").append(comment)); } void Being::setState(const uint8_t state) diff --git a/src/chatlogger.cpp b/src/chatlogger.cpp index 7fd3a6509..a7a660036 100644 --- a/src/chatlogger.cpp +++ b/src/chatlogger.cpp @@ -171,10 +171,11 @@ void ChatLogger::setServerName(const std::string &serverName) secureName(mServerName); if (mLogDir != "") { - DIR *const dir = opendir((mLogDir + dirSeparator - + mServerName).c_str()); + const char *const name = (std::string(mLogDir).append(dirSeparator) + .append(mServerName)).c_str(); + DIR *const dir = opendir(name); if (!dir) - mkdir_r((mLogDir + dirSeparator + mServerName).c_str()); + mkdir_r(name); else closedir(dir); } diff --git a/src/commands.cpp b/src/commands.cpp index e4247bd0e..83160188f 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -817,33 +817,35 @@ impHandler0(uptime) if (days > 0) { if (!str.empty()) - str += ", "; - str += strprintf(ngettext("%d day", "%d days", days), days); + str.append(", "); + str.append(strprintf(ngettext("%d day", "%d days", days), days)); timeDiff -= days * 60 * 60 * 24; } const int hours = timeDiff / 60 / 60; if (hours > 0) { if (!str.empty()) - str += ", "; - str += strprintf(ngettext("%d hour", "%d hours", hours), hours); + str.append(", "); + str.append(strprintf(ngettext("%d hour", "%d hours", + hours), hours)); timeDiff -= hours * 60 * 60; } const int min = timeDiff / 60; if (min > 0) { if (!str.empty()) - str += ", "; - str += strprintf(ngettext("%d minute", "%d minutes", min), min); + str.append(", "); + str.append(strprintf(ngettext("%d minute", "%d minutes", + min), min)); timeDiff -= min * 60; } if (timeDiff > 0) { if (!str.empty()) - str += ", "; - str += strprintf(ngettext("%d second", "%d seconds", - timeDiff), timeDiff); + str.append(", "); + str.append(strprintf(ngettext("%d second", "%d seconds", + timeDiff), timeDiff)); } debugChatTab->chatLog(strprintf(_("Client uptime: %s"), str.c_str())); } @@ -924,7 +926,7 @@ impHandler0(cacheInfo) { const int sz = static_cast<int>(cache[f].size()); all += sz; - str += strprintf("%d: %u, ", f, sz); + str.append(strprintf("%d: %u, ", f, sz)); } } debugChatTab->chatLog(str); @@ -955,37 +957,36 @@ impHandler2(dumpGraphics) mainGraphics->getBpp()); if (mainGraphics->getFullScreen()) - str += "F"; + str.append("F"); else - str += "W"; + str.append("W"); if (mainGraphics->getHWAccel()) - str += "H"; + str.append("H"); else - str += "S"; + str.append("S"); if (mainGraphics->getDoubleBuffer()) - str += "D"; + str.append("D"); else - str += "_"; + str.append("_"); #if defined USE_OPENGL - str += strprintf(",%d", mainGraphics->getOpenGL()); + str.append(strprintf(",%d", mainGraphics->getOpenGL())); #else - str += ",0"; + str.append(",0"); #endif - str += strprintf(",%f,", static_cast<double>(Client::getGuiAlpha())); - str += config.getBoolValue("adjustPerfomance") ? "1" : "0"; - str += config.getBoolValue("alphaCache") ? "1" : "0"; - str += config.getBoolValue("enableMapReduce") ? "1" : "0"; - str += config.getBoolValue("beingopacity") ? "1" : "0"; - str += ","; - str += config.getBoolValue("enableAlphaFix") ? "1" : "0"; - str += config.getBoolValue("disableAdvBeingCaching") ? "1" : "0"; - str += config.getBoolValue("disableBeingCaching") ? "1" : "0"; - str += config.getBoolValue("particleeffects") ? "1" : "0"; - - str += strprintf(",%d-%d", fps, config.getIntValue("fpslimit")); + str.append(strprintf(",%f,", static_cast<double>(Client::getGuiAlpha()))) + .append(config.getBoolValue("adjustPerfomance") ? "1" : "0") + .append(config.getBoolValue("alphaCache") ? "1" : "0") + .append(config.getBoolValue("enableMapReduce") ? "1" : "0") + .append(config.getBoolValue("beingopacity") ? "1" : "0") + .append(",") + .append(config.getBoolValue("enableAlphaFix") ? "1" : "0") + .append(config.getBoolValue("disableAdvBeingCaching") ? "1" : "0") + .append(config.getBoolValue("disableBeingCaching") ? "1" : "0") + .append(config.getBoolValue("particleeffects") ? "1" : "0") + .append(strprintf(",%d-%d", fps, config.getIntValue("fpslimit"))); outStringNormal(tab, str, str); } @@ -1045,9 +1046,10 @@ void showRes(std::string str, ResourceManager::Resources *res) if (!res) return; + str.append(toString(res->size()); if (debugChatTab) - debugChatTab->chatLog(str + toString(res->size())); - logger->log(str + toString(res->size())); + debugChatTab->chatLog(str)); + logger->log(str); ResourceManager::ResourceIterator iter = res->begin(); const ResourceManager::ResourceIterator iter_end = res->end(); while (iter != iter_end) @@ -1161,7 +1163,7 @@ void replaceVars(std::string &str) FOR_EACH (StringVectCIter, it, names) { if (*it != player_node->getName()) - newStr += *it + ","; + newStr.append(*it).append(","); } if (newStr[newStr.size() - 1] == ',') newStr = newStr.substr(0, newStr.size() - 1); @@ -1181,7 +1183,7 @@ void replaceVars(std::string &str) FOR_EACH (StringVectCIter, it, names) { if (*it != player_node->getName()) - newStr += *it + ","; + newStr.append(*it).append(","); } if (newStr[newStr.size() - 1] == ',') newStr = newStr.substr(0, newStr.size() - 1); diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp index c011784ba..11b810caf 100644 --- a/src/inputmanager.cpp +++ b/src/inputmanager.cpp @@ -173,12 +173,12 @@ void InputManager::store() const { if (keyStr.empty()) { - keyStr = tmp + toString(key.value); + keyStr.append(tmp).append(toString(key.value)); } else { - keyStr += strprintf(",%s%d", - tmp.c_str(), key.value); + keyStr.append(strprintf(",%s%d", + tmp.c_str(), key.value)); } } } @@ -318,7 +318,7 @@ std::string InputManager::getKeyStringLong(const int index) const if (keyStr.empty()) keyStr = str; else - keyStr += std::string(" ") + str; + keyStr.append(" ").append(str); } } @@ -357,7 +357,7 @@ std::string InputManager::getKeyValueString(const int index) const if (keyStr.empty()) keyStr = str; else - keyStr += std::string(" ") + str; + keyStr.append(" ").append(str); } } diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp index 96516eadb..03efa63c3 100644 --- a/src/itemshortcut.cpp +++ b/src/itemshortcut.cpp @@ -63,8 +63,9 @@ void ItemShortcut::load(const bool oldConfig) if (mNumber) { - name = "shortcut" + toString(mNumber) + "_"; - color = "shortcutColor" + toString(mNumber) + "_"; + name = std::string("shortcut").append(toString(mNumber)).append("_"); + color = std::string("shortcutColor").append( + toString(mNumber)).append("_"); } else { @@ -88,8 +89,9 @@ void ItemShortcut::save() const std::string color; if (mNumber) { - name = "shortcut" + toString(mNumber) + "_"; - color = "shortcutColor" + toString(mNumber) + "_"; + name = std::string("shortcut").append(toString(mNumber)).append("_"); + color = std::string("shortcutColor").append( + toString(mNumber)).append("_"); } else { diff --git a/src/main.cpp b/src/main.cpp index c940dd6a4..f29735ad8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -248,7 +248,7 @@ int main(int argc, char *argv[]) #ifdef ANDROID mkdir_r(getenv("DATADIR2")); - if (!PHYSFS_init((getRealPath(".") + "/fakebinary").c_str())) + if (!PHYSFS_init((getRealPath(".").append("/fakebinary")).c_str())) #else if (!PHYSFS_init(argv[0])) #endif diff --git a/src/map.cpp b/src/map.cpp index 2812f6eed..c3338f6d4 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -238,12 +238,20 @@ void Map::initializeAmbientLayers() for (int i = 0; /* terminated by a break */; i++) { std::string name; - if (hasProperty("foreground" + toString(i) + "image")) + if (hasProperty(std::string("foreground").append( + toString(i)).append("image"))) + { name = "foreground" + toString(i); - else if (hasProperty("overlay" + toString(i) + "image")) + } + else if (hasProperty(std::string("overlay").append( + toString(i)).append("image"))) + { name = "overlay" + toString(i); + } else + { break; // the FOR loop + } Image *const img = resman->getImage(getProperty(name + "image")); const float speedX = getFloatProperty(name + "scrollX"); @@ -263,9 +271,8 @@ void Map::initializeAmbientLayers() // search for "background*" in map properties - for (int i = 0; - hasProperty("background" + toString(i) + "image"); - i++) + for (int i = 0; hasProperty(std::string("background").append( + toString(i)).append("image")); i ++) { const std::string name = "background" + toString(i); @@ -1113,7 +1120,7 @@ void Map::addExtraLayer() logger->log1("No special layer"); return; } - std::string mapFileName = getUserMapDirectory() + "/extralayer.txt"; + std::string mapFileName = getUserMapDirectory().append("/extralayer.txt"); logger->log("loading extra layer: " + mapFileName); struct stat statbuf; if (!stat(mapFileName.c_str(), &statbuf) && S_ISREG(statbuf.st_mode)) @@ -1143,7 +1150,7 @@ void Map::addExtraLayer() ss >> type1; ss >> comment; while (ss >> buf) - comment += " " + buf; + comment.append(" ").append(buf); const int type = atoi(type1.c_str()); @@ -1183,7 +1190,7 @@ void Map::saveExtraLayer() const logger->log1("No special layer"); return; } - std::string mapFileName = getUserMapDirectory() + "/extralayer.txt"; + std::string mapFileName = getUserMapDirectory().append("/extralayer.txt"); logger->log("saving extra layer: " + mapFileName); if (mkdir_r(getUserMapDirectory().c_str())) @@ -1223,8 +1230,8 @@ void Map::saveExtraLayer() const std::string Map::getUserMapDirectory() const { - return Client::getServerConfigDirectory() + dirSeparator - + getProperty("_realfilename"); + return Client::getServerConfigDirectory() + + dirSeparator + getProperty("_realfilename"); } void Map::addRange(const std::string &name, const int type, diff --git a/src/shopitem.cpp b/src/shopitem.cpp index d0a3cce4d..831b8cd43 100644 --- a/src/shopitem.cpp +++ b/src/shopitem.cpp @@ -38,16 +38,16 @@ ShopItem::ShopItem(const int inventoryIndex, const int id, { if (serverVersion > 0) { - mDisplayName = getInfo().getName(color) + " (" - + Units::formatCurrency(mPrice).c_str() + ") "; + mDisplayName = std::string(getInfo().getName(color)).append(" (") + .append(Units::formatCurrency(mPrice)).append(") "); } else { - mDisplayName = getInfo().getName() + " (" - + Units::formatCurrency(mPrice).c_str() + ") "; + mDisplayName = std::string(getInfo().getName()).append(" (") + .append(Units::formatCurrency(mPrice)).append(") "); } if (quantity > 0) - mDisplayName += "[" + toString(quantity) + "]"; + mDisplayName.append("[").append(toString(quantity)).append("]"); setInvIndex(inventoryIndex); addDuplicate(inventoryIndex, quantity); @@ -60,13 +60,13 @@ ShopItem::ShopItem (const int id, const unsigned char color, const int price) : { if (serverVersion > 0) { - mDisplayName = getInfo().getName(color) + - " (" + Units::formatCurrency(mPrice).c_str() + ")"; + mDisplayName = std::string(getInfo().getName(color)).append(" (") + .append(Units::formatCurrency(mPrice)).append(")"); } else { - mDisplayName = getInfo().getName() + - " (" + Units::formatCurrency(mPrice).c_str() + ")"; + mDisplayName = std::string(getInfo().getName()).append(" (") + .append(Units::formatCurrency(mPrice)).append(")"); } setInvIndex(-1); addDuplicate(-1, 0); @@ -88,16 +88,16 @@ void ShopItem::update() { if (serverVersion > 0) { - mDisplayName = getInfo().getName(mColor) + " (" - + Units::formatCurrency(mPrice).c_str() + ") "; + mDisplayName = std::string(getInfo().getName(mColor)).append(" (") + .append(Units::formatCurrency(mPrice)).append(") "); } else { - mDisplayName = getInfo().getName() + " (" - + Units::formatCurrency(mPrice).c_str() + ") "; + mDisplayName = std::string(getInfo().getName()).append(" (") + .append(Units::formatCurrency(mPrice)).append(") "); } if (mQuantity > 0) - mDisplayName += "[" + toString(mQuantity) + "]"; + mDisplayName.append("[").append(toString(mQuantity)).append("]"); } } diff --git a/src/soundmanager.cpp b/src/soundmanager.cpp index b60e84ef3..62471f07d 100644 --- a/src/soundmanager.cpp +++ b/src/soundmanager.cpp @@ -227,7 +227,7 @@ void SoundManager::setSfxVolume(const int volume) static SDLMusic *loadMusic(const std::string &fileName) { ResourceManager *const resman = ResourceManager::getInstance(); - return resman->getMusic(paths.getStringValue("music") + fileName); + return resman->getMusic(paths.getStringValue("music").append(fileName)); } void SoundManager::playMusic(const std::string &fileName) @@ -335,7 +335,7 @@ void SoundManager::playSfx(const std::string &path, if (!path.compare(0, 4, "sfx/")) tmpPath = path; else - tmpPath = paths.getValue("sfx", "sfx/") + path; + tmpPath = paths.getValue("sfx", "sfx/").append(path); ResourceManager *const resman = ResourceManager::getInstance(); SoundEffect *const sample = resman->getSoundEffect(tmpPath); if (sample) @@ -362,8 +362,8 @@ void SoundManager::playSfx(const std::string &path, void SoundManager::playGuiSound(const std::string &name) { - playGuiSfx(branding.getStringValue("systemsounds") - + config.getStringValue(name) + ".ogg"); + playGuiSfx(branding.getStringValue("systemsounds").append( + config.getStringValue(name)).append(".ogg")); } void SoundManager::playGuiSfx(const std::string &path) @@ -375,7 +375,7 @@ void SoundManager::playGuiSfx(const std::string &path) if (!path.compare(0, 4, "sfx/")) tmpPath = path; else - tmpPath = paths.getValue("sfx", "sfx/") + path; + tmpPath = paths.getValue("sfx", "sfx/").append(path); ResourceManager *const resman = ResourceManager::getInstance(); SoundEffect *const sample = resman->getSoundEffect(tmpPath); if (sample) diff --git a/src/statuseffect.cpp b/src/statuseffect.cpp index e0a4e51a0..e5184bc05 100644 --- a/src/statuseffect.cpp +++ b/src/statuseffect.cpp @@ -76,14 +76,8 @@ AnimatedSprite *StatusEffect::getIcon() const } else { - AnimatedSprite *const sprite = AnimatedSprite::load( - paths.getStringValue("sprites") + mIcon); - if (false && sprite) - { - sprite->play(SpriteAction::DEFAULT); - sprite->reset(); - } - return sprite; + return AnimatedSprite::load(paths.getStringValue( + "sprites").append(mIcon)); } } diff --git a/src/textcommand.cpp b/src/textcommand.cpp index 5cd91b9ef..af2c5a31e 100644 --- a/src/textcommand.cpp +++ b/src/textcommand.cpp @@ -117,7 +117,7 @@ void TextCommand::loadImage() ResourceManager *const resman = ResourceManager::getInstance(); SpriteDisplay display = ItemDB::get(getIcon()).getDisplay(); mImage = resman->getImage(paths.getStringValue("itemIcons") - + display.image); + .append(display.image)); if (!mImage) mImage = Theme::getImageFromTheme("unknown-item.png"); diff --git a/src/units.cpp b/src/units.cpp index b4542658e..4931f416b 100644 --- a/src/units.cpp +++ b/src/units.cpp @@ -205,7 +205,7 @@ static std::string formatUnit(const int value, const int type) if (amount > 0) { output = splitNumber(strprintf("%.*f", pl.round, - amount), pl.separator) + pl.symbol; + amount), pl.separator).append(pl.symbol); } for (unsigned int i = 2; i < ud.levels.size(); i++) @@ -222,7 +222,7 @@ static std::string formatUnit(const int value, const int type) if (levelAmount > 0) { output = splitNumber(strprintf("%d", levelAmount), - pl.separator) + pl.symbol + output; + pl.separator).append(pl.symbol).append(output); } if (!nextAmount) @@ -247,7 +247,7 @@ static std::string formatUnit(const int value, const int type) } return splitNumber(strprintf("%.*f", ul.round, amount), - ul.separator) + ul.symbol; + ul.separator).append(ul.symbol); } } } @@ -278,15 +278,20 @@ static std::string splitNumber(std::string str, const std::string &separator) while (str.size() >= 3) { if (str.size() >= 6) - result = separator + str.substr(str.size() - 3) + result; + { + result = std::string(separator).append(str.substr( + str.size() - 3)).append(result); + } else - result = str.substr(str.size() - 3) + result; + { + result = str.substr(str.size() - 3).append(result); + } str = str.substr(0, str.size() - 3); } if (!str.empty()) { if (!result.empty()) - result = str + separator + result; + result = std::string(str).append(separator).append(result); else result = str; } |