diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index 464a331581..9dbdbfecb0 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -163,7 +163,7 @@ namespace MWClass text += "\n#{sType} "; int skill = MWMechanics::getWeaponType(ref->mBase->mData.mType)->mSkill; - const std::string type = ESM::Skill::sSkillNameIds[skill]; + const std::string& type = ESM::Skill::sSkillNameIds[skill]; std::string_view oneOrTwoHanded; if (weaponType->mWeaponClass == ESM::WeaponType::Melee) { diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 9c4c4a1b7e..1d6b981bcd 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -393,7 +393,7 @@ namespace MWGui const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().find(spellId); - std::string spellName = spell->mName; + const std::string& spellName = spell->mName; if (spellName != mSpellName && mSpellVisible) { mWeaponSpellTimer = 5.0f; @@ -463,7 +463,7 @@ namespace MWGui void HUD::unsetSelectedSpell() { - std::string spellName = "#{sNone}"; + std::string_view spellName = "#{sNone}"; if (spellName != mSpellName && mSpellVisible) { mWeaponSpellTimer = 5.0f; diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index e7e30b76cf..1dfaa0d047 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -791,7 +791,7 @@ namespace MWGui int incr = next ? 1 : -1; bool found = false; - std::string lastId; + std::string_view lastId; if (selected != -1) lastId = model.getItem(selected).mBase.getCellRef().getRefId(); ItemModel::ModelIndex cycled = selected; diff --git a/apps/openmw/mwgui/mainmenu.cpp b/apps/openmw/mwgui/mainmenu.cpp index 8fff838add..d77a2d0bcd 100644 --- a/apps/openmw/mwgui/mainmenu.cpp +++ b/apps/openmw/mwgui/mainmenu.cpp @@ -93,7 +93,7 @@ namespace MWGui { MWBase::WindowManager *winMgr = MWBase::Environment::get().getWindowManager(); - std::string name = *sender->getUserData(); + const std::string& name = *sender->getUserData(); winMgr->playSound("Menu Click"); if (name == "return") { diff --git a/apps/openmw/mwgui/postprocessorhud.cpp b/apps/openmw/mwgui/postprocessorhud.cpp index fc77f1e841..b7a25405b2 100644 --- a/apps/openmw/mwgui/postprocessorhud.cpp +++ b/apps/openmw/mwgui/postprocessorhud.cpp @@ -287,16 +287,16 @@ namespace MWGui while (mConfigArea->getChildCount() > 0) MyGUI::Gui::getInstance().destroyWidget(mConfigArea->getChildAt(0)); - mShaderInfo->setCaption(""); + mShaderInfo->setCaption({}); std::ostringstream ss; - const std::string NA = "#{Interface:NotAvailableShort}"; - const std::string endl = "\n"; + const std::string_view NA = "#{Interface:NotAvailableShort}"; + const char endl = '\n'; - std::string author = technique->getAuthor().empty() ? NA : std::string(technique->getAuthor()); - std::string version = technique->getVersion().empty() ? NA : std::string(technique->getVersion()); - std::string description = technique->getDescription().empty() ? NA : std::string(technique->getDescription()); + std::string_view author = technique->getAuthor().empty() ? NA : technique->getAuthor(); + std::string_view version = technique->getVersion().empty() ? NA : technique->getVersion(); + std::string_view description = technique->getDescription().empty() ? NA : technique->getDescription(); auto serializeBool = [](bool value) { return value ? "#{sYes}" : "#{sNo}"; diff --git a/apps/openmw/mwgui/recharge.cpp b/apps/openmw/mwgui/recharge.cpp index 3b3a754468..4c6a80540d 100644 --- a/apps/openmw/mwgui/recharge.cpp +++ b/apps/openmw/mwgui/recharge.cpp @@ -68,7 +68,7 @@ void Recharge::updateView() { MWWorld::Ptr gem = *mGemIcon->getUserData(); - std::string soul = gem.getCellRef().getSoul(); + const std::string& soul = gem.getCellRef().getSoul(); const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get().find(soul); mChargeLabel->setCaptionWithReplacing("#{sCharges} " + MyGUI::utility::toString(creature->mData.mSoul)); diff --git a/apps/openmw/mwgui/savegamedialog.cpp b/apps/openmw/mwgui/savegamedialog.cpp index 71127c26e1..ffa02f7c55 100644 --- a/apps/openmw/mwgui/savegamedialog.cpp +++ b/apps/openmw/mwgui/savegamedialog.cpp @@ -30,6 +30,7 @@ #include "../mwstate/character.hpp" #include "confirmationdialog.hpp" +#include "ustring.hpp" namespace MWGui { @@ -177,7 +178,7 @@ namespace MWGui // For a custom class, we will not find it in the store (unless we loaded the savegame first). // Fall back to name stored in savegame header in that case. - std::string className; + std::string_view className; if (it->getSignature().mPlayerClassId.empty()) className = it->getSignature().mPlayerClassName; else @@ -191,7 +192,7 @@ namespace MWGui className = "?"; // From an older savegame format that did not support custom classes properly. } - title << " (#{sLevel} " << it->getSignature().mPlayerLevel << " " << MyGUI::TextIterator::toTagsString(className) << ")"; + title << " (#{sLevel} " << it->getSignature().mPlayerLevel << " " << MyGUI::TextIterator::toTagsString(toUString(className)) << ")"; mCharacterSelection->addItem (MyGUI::LanguageManager::getInstance().replaceTags(title.str())); diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp index a646324c13..f24fafb855 100644 --- a/apps/openmw/mwgui/settingswindow.cpp +++ b/apps/openmw/mwgui/settingswindow.cpp @@ -238,7 +238,7 @@ namespace MWGui , mCurrentPage(-1) { bool terrain = Settings::Manager::getBool("distant terrain", "Terrain"); - const std::string widgetName = terrain ? "RenderingDistanceSlider" : "LargeRenderingDistanceSlider"; + const std::string_view widgetName = terrain ? "RenderingDistanceSlider" : "LargeRenderingDistanceSlider"; MyGUI::Widget* unusedSlider; getWidget(unusedSlider, widgetName); unusedSlider->setVisible(false); diff --git a/apps/openmw/mwgui/spellbuyingwindow.cpp b/apps/openmw/mwgui/spellbuyingwindow.cpp index 7bd56c878d..dae157f511 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.cpp +++ b/apps/openmw/mwgui/spellbuyingwindow.cpp @@ -34,10 +34,7 @@ namespace MWGui bool SpellBuyingWindow::sortSpells (const ESM::Spell* left, const ESM::Spell* right) { - std::string leftName = Misc::StringUtils::lowerCase(left->mName); - std::string rightName = Misc::StringUtils::lowerCase(right->mName); - - return leftName.compare(rightName) < 0; + return Misc::StringUtils::ciLess(left->mName, right->mName); } void SpellBuyingWindow::addSpell(const ESM::Spell& spell) diff --git a/apps/openmw/mwgui/spellcreationdialog.cpp b/apps/openmw/mwgui/spellcreationdialog.cpp index 02b6ab8db6..a54c5c87f3 100644 --- a/apps/openmw/mwgui/spellcreationdialog.cpp +++ b/apps/openmw/mwgui/spellcreationdialog.cpp @@ -555,7 +555,7 @@ namespace MWGui for (const short effectId : knownEffects) { - std::string name = MWBase::Environment::get().getWorld ()->getStore ().get().find( + const std::string& name = MWBase::Environment::get().getWorld ()->getStore ().get().find( ESM::MagicEffect::effectIdToString(effectId))->mValue.getString(); MyGUI::Widget* w = mAvailableEffectsList->getItemWidget(name); diff --git a/apps/openmw/mwgui/spellicons.cpp b/apps/openmw/mwgui/spellicons.cpp index 2f1da5857c..60ea47683b 100644 --- a/apps/openmw/mwgui/spellicons.cpp +++ b/apps/openmw/mwgui/spellicons.cpp @@ -149,7 +149,7 @@ namespace MWGui image->setImageTexture(Misc::ResourceHelpers::correctIconPath(effect->mIcon, MWBase::Environment::get().getResourceSystem()->getVFS())); - std::string name = ESM::MagicEffect::effectIdToString (effectId); + const std::string& name = ESM::MagicEffect::effectIdToString(effectId); ToolTipInfo tooltipInfo; tooltipInfo.caption = "#{" + name + "}"; diff --git a/apps/openmw/mwgui/spellwindow.cpp b/apps/openmw/mwgui/spellwindow.cpp index c39341aeb4..20db95fc19 100644 --- a/apps/openmw/mwgui/spellwindow.cpp +++ b/apps/openmw/mwgui/spellwindow.cpp @@ -147,7 +147,7 @@ namespace MWGui MWBase::Environment::get().getWorld()->getStore().get().find(spellId); MWWorld::Ptr player = MWMechanics::getPlayer(); - std::string raceId = player.get()->mBase->mRace; + const std::string& raceId = player.get()->mBase->mRace; const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get().find(raceId); // can't delete racial spells, birthsign spells or powers bool isInherent = race->mPowers.exists(spell->mId) || spell->mData.mType == ESM::Spell::ST_Power; diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 353a88004e..94c4288ddf 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -400,9 +400,9 @@ namespace MWGui else mDynamicToolTipBox->changeWidgetSkin(MWBase::Environment::get().getWindowManager()->isGuiMode() ? "HUD_Box_NoTransp" : "HUD_Box"); - std::string caption = info.caption; - std::string image = info.icon; - int imageSize = (image != "") ? info.imageSize : 0; + const std::string& caption = info.caption; + const std::string& image = info.icon; + int imageSize = (!image.empty()) ? info.imageSize : 0; std::string text = info.text; // remove the first newline (easier this way) @@ -411,7 +411,7 @@ namespace MWGui const ESM::Enchantment* enchant = nullptr; const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); - if (info.enchant != "") + if (!info.enchant.empty()) { enchant = store.get().search(info.enchant); if (enchant) @@ -432,8 +432,8 @@ namespace MWGui const MyGUI::IntPoint padding(8, 8); - const int imageCaptionHPadding = (caption != "" ? 8 : 0); - const int imageCaptionVPadding = (caption != "" ? 4 : 0); + const int imageCaptionHPadding = !caption.empty() ? 8 : 0; + const int imageCaptionVPadding = !caption.empty() ? 4 : 0; const int maximumWidth = MyGUI::RenderManager::getInstance().getViewSize().width - imageCaptionHPadding * 2; @@ -446,7 +446,7 @@ namespace MWGui captionWidget->setCaptionWithReplacing(caption); MyGUI::IntSize captionSize = captionWidget->getTextSize(); - int captionHeight = std::max(caption != "" ? captionSize.height : 0, imageSize); + int captionHeight = std::max(!caption.empty() ? captionSize.height : 0, imageSize); Gui::EditBox* textWidget = mDynamicToolTipBox->createWidget("SandText", MyGUI::IntCoord(0, captionHeight+imageCaptionVPadding, 300, 300-captionHeight-imageCaptionVPadding), MyGUI::Align::Stretch, "ToolTipText"); textWidget->setEditStatic(true); @@ -458,8 +458,8 @@ namespace MWGui MyGUI::IntSize textSize = textWidget->getTextSize(); captionSize += MyGUI::IntSize(imageSize, 0); // adjust for image - MyGUI::IntSize totalSize = MyGUI::IntSize( std::min(std::max(textSize.width,captionSize.width + ((image != "") ? imageCaptionHPadding : 0)),maximumWidth), - ((text != "") ? textSize.height + imageCaptionVPadding : 0) + captionHeight ); + MyGUI::IntSize totalSize = MyGUI::IntSize( std::min(std::max(textSize.width,captionSize.width + ((!image.empty()) ? imageCaptionHPadding : 0)),maximumWidth), + (!text.empty() ? textSize.height + imageCaptionVPadding : 0) + captionHeight ); for (const std::string& note : info.notes) { @@ -578,7 +578,7 @@ namespace MWGui textWidget->setPosition (textWidget->getPosition() + MyGUI::IntPoint(0, padding.top)); // only apply vertical padding, the horizontal works automatically due to Align::HCenter - if (image != "") + if (!image.empty()) { MyGUI::ImageBox* imageWidget = mDynamicToolTipBox->createWidget("ImageBox", MyGUI::IntCoord((totalSize.width - captionSize.width - imageCaptionHPadding)/2, 0, imageSize, imageSize), @@ -611,7 +611,7 @@ namespace MWGui std::string ToolTips::getWeightString(const float weight, const std::string& prefix) { if (weight == 0) - return ""; + return {}; else return "\n" + prefix + ": " + toString(weight); } @@ -619,7 +619,7 @@ namespace MWGui std::string ToolTips::getPercentString(const float value, const std::string& prefix) { if (value == 0) - return ""; + return {}; else return "\n" + prefix + ": " + toString(value*100) +"%"; } @@ -627,15 +627,15 @@ namespace MWGui std::string ToolTips::getValueString(const int value, const std::string& prefix) { if (value == 0) - return ""; + return {}; else return "\n" + prefix + ": " + toString(value); } std::string ToolTips::getMiscString(const std::string& text, const std::string& prefix) { - if (text == "") - return ""; + if (text.empty()) + return {}; else return "\n" + prefix + ": " + text; } @@ -643,7 +643,7 @@ namespace MWGui std::string ToolTips::getCountString(const int value) { if (value == 1) - return ""; + return {}; else return " (" + MyGUI::utility::toString(value) + ")"; } @@ -652,11 +652,11 @@ namespace MWGui { const std::string& soul = cellref.getSoul(); if (soul.empty()) - return std::string(); + return {}; const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); const ESM::Creature *creature = store.get().search(soul); if (!creature) - return std::string(); + return {}; if (creature->mName.empty()) return " (" + creature->mId + ")"; return " (" + creature->mName + ")"; @@ -677,7 +677,7 @@ namespace MWGui if (cellref.getFactionRank() >= 0) { int rank = cellref.getFactionRank(); - const std::string rankName = fact->mRanks[rank]; + const std::string& rankName = fact->mRanks[rank]; if (rankName.empty()) ret += getValueString(cellref.getFactionRank(), "Rank"); else @@ -802,9 +802,9 @@ namespace MWGui if (attributeId == -1) return; - std::string icon = ESM::Attribute::sAttributeIcons[attributeId]; - std::string name = ESM::Attribute::sGmstAttributeIds[attributeId]; - std::string desc = ESM::Attribute::sGmstAttributeDescIds[attributeId]; + const std::string& icon = ESM::Attribute::sAttributeIcons[attributeId]; + const std::string& name = ESM::Attribute::sGmstAttributeIds[attributeId]; + const std::string& desc = ESM::Attribute::sGmstAttributeDescIds[attributeId]; widget->setUserString("ToolTipType", "Layout"); widget->setUserString("ToolTipLayout", "AttributeToolTip"); @@ -850,12 +850,9 @@ namespace MWGui widget->setUserString("ToolTipType", "Layout"); widget->setUserString("ToolTipLayout", "BirthSignToolTip"); widget->setUserString("ImageTexture_BirthSignImage", Misc::ResourceHelpers::correctTexturePath(sign->mTexture, vfs)); - std::string text; + std::string text = sign->mName + "\n#{fontcolourhtml=normal}" + sign->mDescription; - text += sign->mName; - text += "\n#{fontcolourhtml=normal}" + sign->mDescription; - - std::vector abilities, powers, spells; + std::vector abilities, powers, spells; for (const std::string& spellId : sign->mPowers.mList) { @@ -867,35 +864,27 @@ namespace MWGui continue; // We only want spell, ability and powers. if (type == ESM::Spell::ST_Ability) - abilities.push_back(spellId); + abilities.push_back(spell); else if (type == ESM::Spell::ST_Power) - powers.push_back(spellId); + powers.push_back(spell); else if (type == ESM::Spell::ST_Spell) - spells.push_back(spellId); + spells.push_back(spell); } - struct { - const std::vector &spells; - std::string label; - } - categories[3] = { - {abilities, "sBirthsignmenu1"}, - {powers, "sPowers"}, - {spells, "sBirthsignmenu2"} - }; - - for (int category = 0; category < 3; ++category) + using Category = std::pair&, std::string_view>; + for (const auto&[category, label] : std::initializer_list{{abilities, "sBirthsignmenu1"}, {powers, "sPowers"}, {spells, "sBirthsignmenu2"}}) { bool addHeader = true; - for (const std::string& spellId : categories[category].spells) + for (const ESM::Spell* spell : category) { if (addHeader) { - text += std::string("\n\n#{fontcolourhtml=header}") + std::string("#{") + categories[category].label + "}"; + text += "\n\n#{fontcolourhtml=header}#{"; + text += label; + text += '}'; addHeader = false; } - const ESM::Spell *spell = store.get().find(spellId); text += "\n#{fontcolourhtml=normal}" + spell->mName; } } diff --git a/apps/openmw/mwmechanics/aipackage.cpp b/apps/openmw/mwmechanics/aipackage.cpp index 58e8c4d901..edaa481f10 100644 --- a/apps/openmw/mwmechanics/aipackage.cpp +++ b/apps/openmw/mwmechanics/aipackage.cpp @@ -300,7 +300,7 @@ void MWMechanics::AiPackage::openDoors(const MWWorld::Ptr& actor) return; } - const std::string keyId = door.getCellRef().getKey(); + const std::string& keyId = door.getCellRef().getKey(); if (keyId.empty()) return; diff --git a/apps/openmw/mwmechanics/disease.hpp b/apps/openmw/mwmechanics/disease.hpp index 034561ad92..e182886059 100644 --- a/apps/openmw/mwmechanics/disease.hpp +++ b/apps/openmw/mwmechanics/disease.hpp @@ -60,8 +60,7 @@ namespace MWMechanics actor.getClass().getCreatureStats(actor).getSpells().add(spell); MWBase::Environment::get().getWorld()->applyLoopingParticles(actor); - std::string msg = "sMagicContractDisease"; - msg = MWBase::Environment::get().getWorld()->getStore().get().find(msg)->mValue.getString(); + std::string msg = MWBase::Environment::get().getWorld()->getStore().get().find("sMagicContractDisease")->mValue.getString(); msg = Misc::StringUtils::format(msg, spell->mName); MWBase::Environment::get().getWindowManager()->messageBox(msg); } diff --git a/apps/openmw/mwworld/actionsoulgem.cpp b/apps/openmw/mwworld/actionsoulgem.cpp index b416581fa7..dae0a4503f 100644 --- a/apps/openmw/mwworld/actionsoulgem.cpp +++ b/apps/openmw/mwworld/actionsoulgem.cpp @@ -30,7 +30,7 @@ namespace MWWorld } const auto& target = getTarget(); - const std::string targetSoul = target.getCellRef().getSoul(); + const std::string& targetSoul = target.getCellRef().getSoul(); if (targetSoul.empty()) { diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index f1288ee548..5f6df78b50 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -137,7 +137,7 @@ void MWWorld::ContainerStore::storeStates (const CellRefList& collection, } } -const std::string MWWorld::ContainerStore::sGoldId = "gold_001"; +const std::string_view MWWorld::ContainerStore::sGoldId = "gold_001"; MWWorld::ContainerStore::ContainerStore() : mListener(nullptr) diff --git a/apps/openmw/mwworld/containerstore.hpp b/apps/openmw/mwworld/containerstore.hpp index f7f569ec97..94207e1df2 100644 --- a/apps/openmw/mwworld/containerstore.hpp +++ b/apps/openmw/mwworld/containerstore.hpp @@ -90,7 +90,7 @@ namespace MWWorld static constexpr int Type_All = 0xffff; - static const std::string sGoldId; + static const std::string_view sGoldId; protected: ContainerStoreListener* mListener;