From 4ff12d8945644841d47e9ec2ca5d635ea0ae584a Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Tue, 16 Aug 2022 21:15:03 +0200 Subject: [PATCH] Make Class::getName return string_view --- apps/openmw/mwbase/journal.hpp | 3 ++- apps/openmw/mwclass/activator.cpp | 5 +++-- apps/openmw/mwclass/activator.hpp | 2 +- apps/openmw/mwclass/apparatus.cpp | 8 +++++--- apps/openmw/mwclass/apparatus.hpp | 2 +- apps/openmw/mwclass/armor.cpp | 18 ++++++++++++------ apps/openmw/mwclass/armor.hpp | 2 +- apps/openmw/mwclass/bodypart.cpp | 4 ++-- apps/openmw/mwclass/bodypart.hpp | 2 +- apps/openmw/mwclass/book.cpp | 8 +++++--- apps/openmw/mwclass/book.hpp | 2 +- apps/openmw/mwclass/clothing.cpp | 8 +++++--- apps/openmw/mwclass/clothing.hpp | 2 +- apps/openmw/mwclass/container.cpp | 5 +++-- apps/openmw/mwclass/container.hpp | 2 +- apps/openmw/mwclass/creature.cpp | 5 +++-- apps/openmw/mwclass/creature.hpp | 2 +- apps/openmw/mwclass/creaturelevlist.cpp | 4 ++-- apps/openmw/mwclass/creaturelevlist.hpp | 2 +- apps/openmw/mwclass/door.cpp | 11 ++++++----- apps/openmw/mwclass/door.hpp | 2 +- apps/openmw/mwclass/ingredient.cpp | 5 +++-- apps/openmw/mwclass/ingredient.hpp | 2 +- apps/openmw/mwclass/itemlevlist.cpp | 4 ++-- apps/openmw/mwclass/itemlevlist.hpp | 2 +- apps/openmw/mwclass/light.cpp | 7 ++++--- apps/openmw/mwclass/light.hpp | 2 +- apps/openmw/mwclass/lockpick.cpp | 5 +++-- apps/openmw/mwclass/lockpick.hpp | 2 +- apps/openmw/mwclass/misc.cpp | 11 ++++++----- apps/openmw/mwclass/misc.hpp | 2 +- apps/openmw/mwclass/npc.cpp | 5 +++-- apps/openmw/mwclass/npc.hpp | 2 +- apps/openmw/mwclass/potion.cpp | 5 +++-- apps/openmw/mwclass/potion.hpp | 2 +- apps/openmw/mwclass/probe.cpp | 5 +++-- apps/openmw/mwclass/probe.hpp | 2 +- apps/openmw/mwclass/repair.cpp | 5 +++-- apps/openmw/mwclass/repair.hpp | 2 +- apps/openmw/mwclass/static.cpp | 4 ++-- apps/openmw/mwclass/static.hpp | 2 +- apps/openmw/mwclass/weapon.cpp | 12 +++++++----- apps/openmw/mwclass/weapon.hpp | 2 +- apps/openmw/mwdialogue/journalimp.cpp | 2 +- apps/openmw/mwdialogue/journalimp.hpp | 2 +- apps/openmw/mwdialogue/topic.cpp | 2 +- apps/openmw/mwdialogue/topic.hpp | 3 ++- apps/openmw/mwgui/alchemywindow.cpp | 2 +- apps/openmw/mwgui/companionwindow.cpp | 3 ++- apps/openmw/mwgui/container.cpp | 3 ++- apps/openmw/mwgui/enchantingdialog.cpp | 3 ++- apps/openmw/mwgui/hud.cpp | 4 ++-- apps/openmw/mwgui/inventorywindow.cpp | 3 ++- apps/openmw/mwgui/itemchargeview.cpp | 3 ++- apps/openmw/mwgui/layout.cpp | 7 ++++--- apps/openmw/mwgui/layout.hpp | 2 +- apps/openmw/mwgui/merchantrepair.cpp | 4 ++-- apps/openmw/mwgui/tradewindow.cpp | 3 ++- apps/openmw/mwscript/containerextensions.cpp | 4 ++-- apps/openmw/mwworld/actionharvest.cpp | 3 ++- apps/openmw/mwworld/class.hpp | 2 +- components/misc/strings/format.hpp | 7 ++++++- components/misc/utf8stream.hpp | 6 +++--- 63 files changed, 149 insertions(+), 108 deletions(-) diff --git a/apps/openmw/mwbase/journal.hpp b/apps/openmw/mwbase/journal.hpp index ed07392992..acad5c8788 100644 --- a/apps/openmw/mwbase/journal.hpp +++ b/apps/openmw/mwbase/journal.hpp @@ -2,6 +2,7 @@ #define GAME_MWBASE_JOURNAL_H #include +#include #include #include @@ -63,7 +64,7 @@ namespace MWBase virtual void addTopic (const std::string& topicId, const std::string& infoId, const MWWorld::Ptr& actor) = 0; /// \note topicId must be lowercase - virtual void removeLastAddedTopicResponse (const std::string& topicId, const std::string& actorName) = 0; + virtual void removeLastAddedTopicResponse(const std::string& topicId, std::string_view actorName) = 0; ///< Removes the last topic response added for the given topicId and actor name. /// \note topicId must be lowercase diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index 15fd472561..767f0b3da0 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -70,7 +70,7 @@ namespace MWClass return true; } - std::string Activator::getName (const MWWorld::ConstPtr& ptr) const + std::string_view Activator::getName(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); @@ -95,7 +95,8 @@ namespace MWClass const MWWorld::LiveCellRef *ref = ptr.get(); MWGui::ToolTipInfo info; - info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count); + std::string_view name = getName(ptr); + info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count); std::string text; if (MWBase::Environment::get().getWindowManager()->getFullHelp()) diff --git a/apps/openmw/mwclass/activator.hpp b/apps/openmw/mwclass/activator.hpp index 824f510dfd..12dce7a893 100644 --- a/apps/openmw/mwclass/activator.hpp +++ b/apps/openmw/mwclass/activator.hpp @@ -23,7 +23,7 @@ namespace MWClass void insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) const override; - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. bool hasToolTip (const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index 14fcea07db..37ceab077f 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -39,7 +39,7 @@ namespace MWClass return getClassModel(ptr); } - std::string Apparatus::getName (const MWWorld::ConstPtr& ptr) const + std::string_view Apparatus::getName(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); const std::string& name = ref->mBase->mName; @@ -89,7 +89,8 @@ namespace MWClass const MWWorld::LiveCellRef *ref = ptr.get(); MWGui::ToolTipInfo info; - info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count); + std::string_view name = getName(ptr); + info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count); info.icon = ref->mBase->mIcon; std::string text; @@ -97,7 +98,8 @@ namespace MWClass text += MWGui::ToolTips::getWeightString(ref->mBase->mData.mWeight, "#{sWeight}"); text += MWGui::ToolTips::getValueString(ref->mBase->mData.mValue, "#{sValue}"); - if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { + if (MWBase::Environment::get().getWindowManager()->getFullHelp()) + { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } diff --git a/apps/openmw/mwclass/apparatus.hpp b/apps/openmw/mwclass/apparatus.hpp index 1f9e907b06..d3ca9e6d69 100644 --- a/apps/openmw/mwclass/apparatus.hpp +++ b/apps/openmw/mwclass/apparatus.hpp @@ -20,7 +20,7 @@ namespace MWClass void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override; ///< Add reference into a cell for rendering - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. std::unique_ptr activate (const MWWorld::Ptr& ptr, diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index 6ab731d0bd..59977cf7ea 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -47,7 +47,7 @@ namespace MWClass return getClassModel(ptr); } - std::string Armor::getName (const MWWorld::ConstPtr& ptr) const + std::string_view Armor::getName(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); const std::string& name = ref->mBase->mName; @@ -195,13 +195,14 @@ namespace MWClass const MWWorld::LiveCellRef *ref = ptr.get(); MWGui::ToolTipInfo info; - info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count); + std::string_view name = getName(ptr); + info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count); info.icon = ref->mBase->mIcon; std::string text; // get armor type string (light/medium/heavy) - std::string typeText; + std::string_view typeText; if (ref->mBase->mData.mWeight == 0) { // no type @@ -224,12 +225,17 @@ namespace MWClass text += "\n#{sCondition}: " + MWGui::ToolTips::toString(remainingHealth) + "/" + MWGui::ToolTips::toString(ref->mBase->mData.mHealth); - if (typeText != "") - text += "\n#{sWeight}: " + MWGui::ToolTips::toString(ref->mBase->mData.mWeight) + " (" + typeText + ")"; + if (!typeText.empty()) + { + text += "\n#{sWeight}: " + MWGui::ToolTips::toString(ref->mBase->mData.mWeight) + " ("; + text += typeText; + text += ')'; + } text += MWGui::ToolTips::getValueString(ref->mBase->mData.mValue, "#{sValue}"); - if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { + if (MWBase::Environment::get().getWindowManager()->getFullHelp()) + { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } diff --git a/apps/openmw/mwclass/armor.hpp b/apps/openmw/mwclass/armor.hpp index 2c1bb965ae..30a9f5fc57 100644 --- a/apps/openmw/mwclass/armor.hpp +++ b/apps/openmw/mwclass/armor.hpp @@ -20,7 +20,7 @@ namespace MWClass void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override; ///< Add reference into a cell for rendering - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. std::unique_ptr activate (const MWWorld::Ptr& ptr, diff --git a/apps/openmw/mwclass/bodypart.cpp b/apps/openmw/mwclass/bodypart.cpp index d9438f80c1..c341799ab4 100644 --- a/apps/openmw/mwclass/bodypart.cpp +++ b/apps/openmw/mwclass/bodypart.cpp @@ -28,9 +28,9 @@ namespace MWClass } } - std::string BodyPart::getName(const MWWorld::ConstPtr &ptr) const + std::string_view BodyPart::getName(const MWWorld::ConstPtr &ptr) const { - return std::string(); + return {}; } bool BodyPart::hasToolTip(const MWWorld::ConstPtr& ptr) const diff --git a/apps/openmw/mwclass/bodypart.hpp b/apps/openmw/mwclass/bodypart.hpp index fb6c813f53..5491ccf8b6 100644 --- a/apps/openmw/mwclass/bodypart.hpp +++ b/apps/openmw/mwclass/bodypart.hpp @@ -19,7 +19,7 @@ namespace MWClass void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override; ///< Add reference into a cell for rendering - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName (const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. bool hasToolTip (const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index d87a1c5d19..8cb9623755 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -44,7 +44,7 @@ namespace MWClass return getClassModel(ptr); } - std::string Book::getName (const MWWorld::ConstPtr& ptr) const + std::string_view Book::getName(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); const std::string& name = ref->mBase->mName; @@ -106,7 +106,8 @@ namespace MWClass const MWWorld::LiveCellRef *ref = ptr.get(); MWGui::ToolTipInfo info; - info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count); + std::string_view name = getName(ptr); + info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count); info.icon = ref->mBase->mIcon; std::string text; @@ -114,7 +115,8 @@ namespace MWClass text += MWGui::ToolTips::getWeightString(ref->mBase->mData.mWeight, "#{sWeight}"); text += MWGui::ToolTips::getValueString(ref->mBase->mData.mValue, "#{sValue}"); - if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { + if (MWBase::Environment::get().getWindowManager()->getFullHelp()) + { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } diff --git a/apps/openmw/mwclass/book.hpp b/apps/openmw/mwclass/book.hpp index 5d028d6699..976b6bcb58 100644 --- a/apps/openmw/mwclass/book.hpp +++ b/apps/openmw/mwclass/book.hpp @@ -18,7 +18,7 @@ namespace MWClass void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override; ///< Add reference into a cell for rendering - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. std::unique_ptr activate (const MWWorld::Ptr& ptr, diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index 9e77b1d898..33ea292258 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -42,7 +42,7 @@ namespace MWClass return getClassModel(ptr); } - std::string Clothing::getName (const MWWorld::ConstPtr& ptr) const + std::string_view Clothing::getName(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); const std::string& name = ref->mBase->mName; @@ -153,7 +153,8 @@ namespace MWClass const MWWorld::LiveCellRef *ref = ptr.get(); MWGui::ToolTipInfo info; - info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count); + std::string_view name = getName(ptr); + info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count); info.icon = ref->mBase->mIcon; std::string text; @@ -161,7 +162,8 @@ namespace MWClass text += MWGui::ToolTips::getWeightString(ref->mBase->mData.mWeight, "#{sWeight}"); text += MWGui::ToolTips::getValueString(ref->mBase->mData.mValue, "#{sValue}"); - if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { + if (MWBase::Environment::get().getWindowManager()->getFullHelp()) + { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } diff --git a/apps/openmw/mwclass/clothing.hpp b/apps/openmw/mwclass/clothing.hpp index be486a740e..731291fdd9 100644 --- a/apps/openmw/mwclass/clothing.hpp +++ b/apps/openmw/mwclass/clothing.hpp @@ -18,7 +18,7 @@ namespace MWClass void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override; ///< Add reference into a cell for rendering - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. std::unique_ptr activate (const MWWorld::Ptr& ptr, diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index 932b160e32..1d352035aa 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -210,7 +210,7 @@ namespace MWClass } } - std::string Container::getName (const MWWorld::ConstPtr& ptr) const + std::string_view Container::getName(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); const std::string& name = ref->mBase->mName; @@ -245,7 +245,8 @@ namespace MWClass const MWWorld::LiveCellRef *ref = ptr.get(); MWGui::ToolTipInfo info; - info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)); + std::string_view name = getName(ptr); + info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}); std::string text; int lockLevel = ptr.getCellRef().getLockLevel(); diff --git a/apps/openmw/mwclass/container.hpp b/apps/openmw/mwclass/container.hpp index 2573eeb47e..029e86c9e2 100644 --- a/apps/openmw/mwclass/container.hpp +++ b/apps/openmw/mwclass/container.hpp @@ -47,7 +47,7 @@ namespace MWClass void insertObject(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) const override; void insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) const override; - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. std::unique_ptr activate (const MWWorld::Ptr& ptr, diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index c03dac2a9c..07a216a3f1 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -211,7 +211,7 @@ namespace MWClass } } - std::string Creature::getName (const MWWorld::ConstPtr& ptr) const + std::string_view Creature::getName(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); const std::string& name = ref->mBase->mName; @@ -589,7 +589,8 @@ namespace MWClass const MWWorld::LiveCellRef *ref = ptr.get(); MWGui::ToolTipInfo info; - info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)); + std::string_view name = getName(ptr); + info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}); std::string text; if (MWBase::Environment::get().getWindowManager()->getFullHelp()) diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index 84119c9fe8..d578e262b6 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -51,7 +51,7 @@ namespace MWClass void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override; ///< Add reference into a cell for rendering - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. bool hasToolTip(const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/creaturelevlist.cpp b/apps/openmw/mwclass/creaturelevlist.cpp index 431f9675b6..822ced836d 100644 --- a/apps/openmw/mwclass/creaturelevlist.cpp +++ b/apps/openmw/mwclass/creaturelevlist.cpp @@ -57,9 +57,9 @@ namespace MWClass MWBase::Environment::get().getWorld()->adjustPosition(creature, force); } - std::string CreatureLevList::getName (const MWWorld::ConstPtr& ptr) const + std::string_view CreatureLevList::getName(const MWWorld::ConstPtr& ptr) const { - return ""; + return {}; } bool CreatureLevList::hasToolTip(const MWWorld::ConstPtr& ptr) const diff --git a/apps/openmw/mwclass/creaturelevlist.hpp b/apps/openmw/mwclass/creaturelevlist.hpp index 81c2f80070..c8ee3b9b7a 100644 --- a/apps/openmw/mwclass/creaturelevlist.hpp +++ b/apps/openmw/mwclass/creaturelevlist.hpp @@ -15,7 +15,7 @@ namespace MWClass public: - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. bool hasToolTip (const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index cf9d197b30..6ce5d8d4bb 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -100,7 +100,7 @@ namespace MWClass return getClassModel(ptr); } - std::string Door::getName (const MWWorld::ConstPtr& ptr) const + std::string_view Door::getName(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); const std::string& name = ref->mBase->mName; @@ -115,8 +115,8 @@ namespace MWClass const std::string &openSound = ref->mBase->mOpenSound; const std::string &closeSound = ref->mBase->mCloseSound; - const std::string lockedSound = "LockedDoor"; - const std::string trapActivationSound = "Disarm Trap Fail"; + const std::string_view lockedSound = "LockedDoor"; + const std::string_view trapActivationSound = "Disarm Trap Fail"; MWWorld::ContainerStore &invStore = actor.getClass().getContainerStore(actor); @@ -267,7 +267,8 @@ namespace MWClass const MWWorld::LiveCellRef *ref = ptr.get(); MWGui::ToolTipInfo info; - info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)); + std::string_view name = getName(ptr); + info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}); std::string text; @@ -282,7 +283,7 @@ namespace MWClass text += "\n#{sLockLevel}: " + MWGui::ToolTips::toString(ptr.getCellRef().getLockLevel()); else if (ptr.getCellRef().getLockLevel() < 0) text += "\n#{sUnlocked}"; - if (ptr.getCellRef().getTrap() != "") + if (!ptr.getCellRef().getTrap().empty()) text += "\n#{sTrapped}"; if (MWBase::Environment::get().getWindowManager()->getFullHelp()) diff --git a/apps/openmw/mwclass/door.hpp b/apps/openmw/mwclass/door.hpp index b490060153..4ffa2bd02e 100644 --- a/apps/openmw/mwclass/door.hpp +++ b/apps/openmw/mwclass/door.hpp @@ -29,7 +29,7 @@ namespace MWClass bool useAnim() const override; - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. std::unique_ptr activate (const MWWorld::Ptr& ptr, diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index 4b523335af..5ac9d36540 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -41,7 +41,7 @@ namespace MWClass return getClassModel(ptr); } - std::string Ingredient::getName (const MWWorld::ConstPtr& ptr) const + std::string_view Ingredient::getName(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); const std::string& name = ref->mBase->mName; @@ -101,7 +101,8 @@ namespace MWClass const MWWorld::LiveCellRef *ref = ptr.get(); MWGui::ToolTipInfo info; - info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count); + std::string_view name = getName(ptr); + info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count); info.icon = ref->mBase->mIcon; std::string text; diff --git a/apps/openmw/mwclass/ingredient.hpp b/apps/openmw/mwclass/ingredient.hpp index 15a879ba94..4dc3961ee4 100644 --- a/apps/openmw/mwclass/ingredient.hpp +++ b/apps/openmw/mwclass/ingredient.hpp @@ -18,7 +18,7 @@ namespace MWClass void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override; ///< Add reference into a cell for rendering - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. std::unique_ptr activate (const MWWorld::Ptr& ptr, diff --git a/apps/openmw/mwclass/itemlevlist.cpp b/apps/openmw/mwclass/itemlevlist.cpp index 2624be4aa8..95b8e22402 100644 --- a/apps/openmw/mwclass/itemlevlist.cpp +++ b/apps/openmw/mwclass/itemlevlist.cpp @@ -9,9 +9,9 @@ namespace MWClass { } - std::string ItemLevList::getName (const MWWorld::ConstPtr& ptr) const + std::string_view ItemLevList::getName(const MWWorld::ConstPtr& ptr) const { - return ""; + return {}; } bool ItemLevList::hasToolTip(const MWWorld::ConstPtr& ptr) const diff --git a/apps/openmw/mwclass/itemlevlist.hpp b/apps/openmw/mwclass/itemlevlist.hpp index d7377bbcb4..dbaf6f54c4 100644 --- a/apps/openmw/mwclass/itemlevlist.hpp +++ b/apps/openmw/mwclass/itemlevlist.hpp @@ -13,7 +13,7 @@ namespace MWClass public: - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. bool hasToolTip (const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index 6694c68c0b..31675a4ee1 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -72,12 +72,12 @@ namespace MWClass return getClassModel(ptr); } - std::string Light::getName (const MWWorld::ConstPtr& ptr) const + std::string_view Light::getName(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); if (ref->mBase->mModel.empty()) - return std::string(); + return {}; const std::string& name = ref->mBase->mName; return !name.empty() ? name : ref->mBase->mId; @@ -150,7 +150,8 @@ namespace MWClass const MWWorld::LiveCellRef *ref = ptr.get(); MWGui::ToolTipInfo info; - info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count); + std::string_view name = getName(ptr); + info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count); info.icon = ref->mBase->mIcon; std::string text; diff --git a/apps/openmw/mwclass/light.hpp b/apps/openmw/mwclass/light.hpp index 81b1f0fd92..d4aba148db 100644 --- a/apps/openmw/mwclass/light.hpp +++ b/apps/openmw/mwclass/light.hpp @@ -23,7 +23,7 @@ namespace MWClass bool useAnim() const override; - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. bool hasToolTip (const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index d97d207695..dabf25e672 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -41,7 +41,7 @@ namespace MWClass return getClassModel(ptr); } - std::string Lockpick::getName (const MWWorld::ConstPtr& ptr) const + std::string_view Lockpick::getName(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); const std::string& name = ref->mBase->mName; @@ -100,7 +100,8 @@ namespace MWClass const MWWorld::LiveCellRef *ref = ptr.get(); MWGui::ToolTipInfo info; - info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count); + std::string_view name = getName(ptr); + info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count); info.icon = ref->mBase->mIcon; std::string text; diff --git a/apps/openmw/mwclass/lockpick.hpp b/apps/openmw/mwclass/lockpick.hpp index 66a5652068..7521a4c04c 100644 --- a/apps/openmw/mwclass/lockpick.hpp +++ b/apps/openmw/mwclass/lockpick.hpp @@ -18,7 +18,7 @@ namespace MWClass void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override; ///< Add reference into a cell for rendering - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. std::unique_ptr activate (const MWWorld::Ptr& ptr, diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index 4897b016ae..fe8c3847f0 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -51,7 +51,7 @@ namespace MWClass return getClassModel(ptr); } - std::string Miscellaneous::getName (const MWWorld::ConstPtr& ptr) const + std::string_view Miscellaneous::getName(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); const std::string& name = ref->mBase->mName; @@ -80,7 +80,7 @@ namespace MWClass if (ptr.getCellRef().getGoldValue() > 1 && ptr.getRefData().getCount() == 1) value = ptr.getCellRef().getGoldValue(); - if (ptr.getCellRef().getSoul() != "") + if (!ptr.getCellRef().getSoul().empty()) { const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get().search(ref->mRef.getSoul()); if (creature) @@ -142,7 +142,8 @@ namespace MWClass else // gold displays its count also if it's 1. countString = " (" + std::to_string(count) + ")"; - info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + countString + MWGui::ToolTips::getSoulString(ptr.getCellRef()); + std::string_view name = getName(ptr); + info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count); info.icon = ref->mBase->mIcon; std::string text; @@ -171,7 +172,7 @@ namespace MWClass if (isGold(ptr)) { int goldAmount = getValue(ptr) * count; - std::string base = "Gold_001"; + std::string_view base = "Gold_001"; if (goldAmount >= 100) base = "Gold_100"; else if (goldAmount >= 25) @@ -203,7 +204,7 @@ namespace MWClass std::unique_ptr Miscellaneous::use (const MWWorld::Ptr& ptr, bool force) const { - const std::string soulgemPrefix = "misc_soulgem"; + const std::string_view soulgemPrefix = "misc_soulgem"; if (::Misc::StringUtils::ciCompareLen(ptr.getCellRef().getRefId(), soulgemPrefix, soulgemPrefix.length()) == 0) return std::make_unique(ptr); diff --git a/apps/openmw/mwclass/misc.hpp b/apps/openmw/mwclass/misc.hpp index deae059d07..62caa52cc9 100644 --- a/apps/openmw/mwclass/misc.hpp +++ b/apps/openmw/mwclass/misc.hpp @@ -18,7 +18,7 @@ namespace MWClass void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override; ///< Add reference into a cell for rendering - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. std::unique_ptr activate (const MWWorld::Ptr& ptr, diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 53b6f8b0fa..823babe83a 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -523,7 +523,7 @@ namespace MWClass } - std::string Npc::getName (const MWWorld::ConstPtr& ptr) const + std::string_view Npc::getName(const MWWorld::ConstPtr& ptr) const { if(ptr.getRefData().getCustomData() && ptr.getRefData().getCustomData()->asNpcCustomData().mNpcStats.isWerewolf()) { @@ -1117,7 +1117,8 @@ namespace MWClass bool fullHelp = MWBase::Environment::get().getWindowManager()->getFullHelp(); MWGui::ToolTipInfo info; - info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)); + std::string_view name = getName(ptr); + info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}); if(fullHelp && !ref->mBase->mName.empty() && ptr.getRefData().getCustomData() && ptr.getRefData().getCustomData()->asNpcCustomData().mNpcStats.isWerewolf()) { info.caption += " ("; diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index 40788a7aaa..5b05b0cdc2 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -53,7 +53,7 @@ namespace MWClass void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override; ///< Add reference into a cell for rendering - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. MWMechanics::CreatureStats& getCreatureStats (const MWWorld::Ptr& ptr) const override; diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index 0902651e9c..583005e17e 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -43,7 +43,7 @@ namespace MWClass return getClassModel(ptr); } - std::string Potion::getName (const MWWorld::ConstPtr& ptr) const + std::string_view Potion::getName(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); const std::string& name = ref->mBase->mName; @@ -94,7 +94,8 @@ namespace MWClass const MWWorld::LiveCellRef *ref = ptr.get(); MWGui::ToolTipInfo info; - info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count); + std::string_view name = getName(ptr); + info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count); info.icon = ref->mBase->mIcon; std::string text; diff --git a/apps/openmw/mwclass/potion.hpp b/apps/openmw/mwclass/potion.hpp index 9dabe28e5d..49a7a9bf87 100644 --- a/apps/openmw/mwclass/potion.hpp +++ b/apps/openmw/mwclass/potion.hpp @@ -18,7 +18,7 @@ namespace MWClass void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override; ///< Add reference into a cell for rendering - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. std::unique_ptr activate (const MWWorld::Ptr& ptr, diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp index 73bd911203..56ca071f8c 100644 --- a/apps/openmw/mwclass/probe.cpp +++ b/apps/openmw/mwclass/probe.cpp @@ -41,7 +41,7 @@ namespace MWClass return getClassModel(ptr); } - std::string Probe::getName (const MWWorld::ConstPtr& ptr) const + std::string_view Probe::getName(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); const std::string& name = ref->mBase->mName; @@ -100,7 +100,8 @@ namespace MWClass const MWWorld::LiveCellRef *ref = ptr.get(); MWGui::ToolTipInfo info; - info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count); + std::string_view name = getName(ptr); + info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count); info.icon = ref->mBase->mIcon; std::string text; diff --git a/apps/openmw/mwclass/probe.hpp b/apps/openmw/mwclass/probe.hpp index 5922fa9899..c4ae01ccac 100644 --- a/apps/openmw/mwclass/probe.hpp +++ b/apps/openmw/mwclass/probe.hpp @@ -18,7 +18,7 @@ namespace MWClass void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override; ///< Add reference into a cell for rendering - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. std::unique_ptr activate (const MWWorld::Ptr& ptr, diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index 4977092d60..b182b2d9d9 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -38,7 +38,7 @@ namespace MWClass return getClassModel(ptr); } - std::string Repair::getName (const MWWorld::ConstPtr& ptr) const + std::string_view Repair::getName(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); const std::string& name = ref->mBase->mName; @@ -101,7 +101,8 @@ namespace MWClass const MWWorld::LiveCellRef *ref = ptr.get(); MWGui::ToolTipInfo info; - info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count); + std::string_view name = getName(ptr); + info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count); info.icon = ref->mBase->mIcon; std::string text; diff --git a/apps/openmw/mwclass/repair.hpp b/apps/openmw/mwclass/repair.hpp index eec8c4fce0..61d63a2cea 100644 --- a/apps/openmw/mwclass/repair.hpp +++ b/apps/openmw/mwclass/repair.hpp @@ -18,7 +18,7 @@ namespace MWClass void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override; ///< Add reference into a cell for rendering - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. std::unique_ptr activate (const MWWorld::Ptr& ptr, diff --git a/apps/openmw/mwclass/static.cpp b/apps/openmw/mwclass/static.cpp index f587199237..1d1e45d7f7 100644 --- a/apps/openmw/mwclass/static.cpp +++ b/apps/openmw/mwclass/static.cpp @@ -44,9 +44,9 @@ namespace MWClass return getClassModel(ptr); } - std::string Static::getName (const MWWorld::ConstPtr& ptr) const + std::string_view Static::getName(const MWWorld::ConstPtr& ptr) const { - return ""; + return {}; } bool Static::hasToolTip(const MWWorld::ConstPtr& ptr) const diff --git a/apps/openmw/mwclass/static.hpp b/apps/openmw/mwclass/static.hpp index 6dbeb46662..88cf982d1c 100644 --- a/apps/openmw/mwclass/static.hpp +++ b/apps/openmw/mwclass/static.hpp @@ -21,7 +21,7 @@ namespace MWClass void insertObject(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) const override; void insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) const override; - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. bool hasToolTip (const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index d734acc229..a3749fd2d4 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -47,7 +47,7 @@ namespace MWClass return getClassModel(ptr); } - std::string Weapon::getName (const MWWorld::ConstPtr& ptr) const + std::string_view Weapon::getName(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); const std::string& name = ref->mBase->mName; @@ -150,7 +150,8 @@ namespace MWClass const ESM::WeaponType* weaponType = MWMechanics::getWeaponType(ref->mBase->mData.mType); MWGui::ToolTipInfo info; - info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count); + std::string_view name = getName(ptr); + info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count); info.icon = ref->mBase->mIcon; const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); @@ -164,7 +165,7 @@ namespace MWClass int skill = MWMechanics::getWeaponType(ref->mBase->mData.mType)->mSkill; const std::string type = ESM::Skill::sSkillNameIds[skill]; - std::string oneOrTwoHanded; + std::string_view oneOrTwoHanded; if (weaponType->mWeaponClass == ESM::WeaponType::Melee) { if (weaponType->mFlags & ESM::WeaponType::TwoHanded) @@ -173,8 +174,9 @@ namespace MWClass oneOrTwoHanded = "sOneHanded"; } - text += store.get().find(type)->mValue.getString() + - ((oneOrTwoHanded != "") ? ", " + store.get().find(oneOrTwoHanded)->mValue.getString() : ""); + text += store.get().find(type)->mValue.getString(); + if (!oneOrTwoHanded.empty()) + text += ", " + store.get().find(oneOrTwoHanded)->mValue.getString(); // weapon damage if (weaponType->mWeaponClass == ESM::WeaponType::Thrown) diff --git a/apps/openmw/mwclass/weapon.hpp b/apps/openmw/mwclass/weapon.hpp index 246f9abeda..d067430a1b 100644 --- a/apps/openmw/mwclass/weapon.hpp +++ b/apps/openmw/mwclass/weapon.hpp @@ -18,7 +18,7 @@ namespace MWClass void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override; ///< Add reference into a cell for rendering - std::string getName (const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; ///< \return name or ID; can return an empty string. std::unique_ptr activate (const MWWorld::Ptr& ptr, diff --git a/apps/openmw/mwdialogue/journalimp.cpp b/apps/openmw/mwdialogue/journalimp.cpp index 1d458b2ebc..e1a17dd68f 100644 --- a/apps/openmw/mwdialogue/journalimp.cpp +++ b/apps/openmw/mwdialogue/journalimp.cpp @@ -130,7 +130,7 @@ namespace MWDialogue topic.addEntry (entry); } - void Journal::removeLastAddedTopicResponse(const std::string &topicId, const std::string &actorName) + void Journal::removeLastAddedTopicResponse(const std::string &topicId, std::string_view actorName) { Topic& topic = getTopic (topicId); diff --git a/apps/openmw/mwdialogue/journalimp.hpp b/apps/openmw/mwdialogue/journalimp.hpp index 0c778d2ba2..18bbe8b2f2 100644 --- a/apps/openmw/mwdialogue/journalimp.hpp +++ b/apps/openmw/mwdialogue/journalimp.hpp @@ -41,7 +41,7 @@ namespace MWDialogue void addTopic (const std::string& topicId, const std::string& infoId, const MWWorld::Ptr& actor) override; /// \note topicId must be lowercase - void removeLastAddedTopicResponse (const std::string& topicId, const std::string& actorName) override; + void removeLastAddedTopicResponse(const std::string& topicId, std::string_view actorName) override; ///< Removes the last topic response added for the given topicId and actor name. /// \note topicId must be lowercase diff --git a/apps/openmw/mwdialogue/topic.cpp b/apps/openmw/mwdialogue/topic.cpp index 9d56028184..c9d9b2c9df 100644 --- a/apps/openmw/mwdialogue/topic.cpp +++ b/apps/openmw/mwdialogue/topic.cpp @@ -59,7 +59,7 @@ namespace MWDialogue return mEntries.end(); } - void Topic::removeLastAddedResponse (const std::string& actorName) + void Topic::removeLastAddedResponse(std::string_view actorName) { for (std::vector::reverse_iterator it = mEntries.rbegin(); it != mEntries.rend(); ++it) diff --git a/apps/openmw/mwdialogue/topic.hpp b/apps/openmw/mwdialogue/topic.hpp index 12df484aa7..4e5c936ecd 100644 --- a/apps/openmw/mwdialogue/topic.hpp +++ b/apps/openmw/mwdialogue/topic.hpp @@ -2,6 +2,7 @@ #define GAME_MWDIALOG_TOPIC_H #include +#include #include #include "journalentry.hpp" @@ -48,7 +49,7 @@ namespace MWDialogue virtual std::string getName() const; - void removeLastAddedResponse (const std::string& actorName); + void removeLastAddedResponse(std::string_view actorName); TEntryIter begin() const; ///< Iterator pointing to the begin of the journal for this topic. diff --git a/apps/openmw/mwgui/alchemywindow.cpp b/apps/openmw/mwgui/alchemywindow.cpp index ac1ebd2038..5c4ea49c70 100644 --- a/apps/openmw/mwgui/alchemywindow.cpp +++ b/apps/openmw/mwgui/alchemywindow.cpp @@ -197,7 +197,7 @@ namespace MWGui if (item.getType() != ESM::Ingredient::sRecordId) continue; - itemNames.insert(item.getClass().getName(item)); + itemNames.emplace(item.getClass().getName(item)); MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr(); auto const alchemySkill = player.getClass().getSkill(player, ESM::Skill::Alchemy); diff --git a/apps/openmw/mwgui/companionwindow.cpp b/apps/openmw/mwgui/companionwindow.cpp index 4951dbfd12..45c5eb9f83 100644 --- a/apps/openmw/mwgui/companionwindow.cpp +++ b/apps/openmw/mwgui/companionwindow.cpp @@ -89,7 +89,8 @@ void CompanionWindow::onItemSelected(int index) if (count > 1 && !shift) { CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog(); - std::string name = object.getClass().getName(object) + MWGui::ToolTips::getSoulString(object.getCellRef()); + std::string name{object.getClass().getName(object)}; + name += MWGui::ToolTips::getSoulString(object.getCellRef()); dialog->openCountDialog(name, "#{sTake}", count); dialog->eventOkClicked.clear(); dialog->eventOkClicked += MyGUI::newDelegate(this, &CompanionWindow::dragItem); diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index fafeb8b1ce..8478fc46e0 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -83,7 +83,8 @@ namespace MWGui if (count > 1 && !shift) { CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog(); - std::string name = object.getClass().getName(object) + MWGui::ToolTips::getSoulString(object.getCellRef()); + std::string name{object.getClass().getName(object)}; + name += MWGui::ToolTips::getSoulString(object.getCellRef()); dialog->openCountDialog(name, "#{sTake}", count); dialog->eventOkClicked.clear(); dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerWindow::dragItem); diff --git a/apps/openmw/mwgui/enchantingdialog.cpp b/apps/openmw/mwgui/enchantingdialog.cpp index 6c81036eba..4149ba9c07 100644 --- a/apps/openmw/mwgui/enchantingdialog.cpp +++ b/apps/openmw/mwgui/enchantingdialog.cpp @@ -98,7 +98,8 @@ namespace MWGui } else { - mName->setCaption(item.getClass().getName(item)); + std::string_view name = item.getClass().getName(item); + mName->setCaption({name.data(), name.size()}); mItemBox->setItem(item); mItemBox->setUserString ("ToolTipType", "ItemPtr"); mItemBox->setUserData(MWWorld::Ptr(item)); diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 989cd8e258..9c4c4a1b7e 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -422,7 +422,7 @@ namespace MWGui void HUD::setSelectedEnchantItem(const MWWorld::Ptr& item, int chargePercent) { - std::string itemName = item.getClass().getName(item); + std::string_view itemName = item.getClass().getName(item); if (itemName != mSpellName && mSpellVisible) { mWeaponSpellTimer = 5.0f; @@ -442,7 +442,7 @@ namespace MWGui void HUD::setSelectedWeapon(const MWWorld::Ptr& item, int durabilityPercent) { - std::string itemName = item.getClass().getName(item); + std::string_view itemName = item.getClass().getName(item); if (itemName != mWeaponName && mWeaponVisible) { mWeaponSpellTimer = 5.0f; diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 1063e8e4fe..a359efae52 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -293,7 +293,8 @@ namespace MWGui { CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog(); std::string message = mTrading ? "#{sQuanityMenuMessage01}" : "#{sTake}"; - std::string name = object.getClass().getName(object) + MWGui::ToolTips::getSoulString(object.getCellRef()); + std::string name{object.getClass().getName(object)}; + name += MWGui::ToolTips::getSoulString(object.getCellRef()); dialog->openCountDialog(name, message, count); dialog->eventOkClicked.clear(); if (mTrading) diff --git a/apps/openmw/mwgui/itemchargeview.cpp b/apps/openmw/mwgui/itemchargeview.cpp index 5f9788bc45..62d1d069e1 100644 --- a/apps/openmw/mwgui/itemchargeview.cpp +++ b/apps/openmw/mwgui/itemchargeview.cpp @@ -169,7 +169,8 @@ namespace MWGui void ItemChargeView::updateLine(const ItemChargeView::Line& line) { - line.mText->setCaption(line.mItemPtr.getClass().getName(line.mItemPtr)); + std::string_view name = line.mItemPtr.getClass().getName(line.mItemPtr); + line.mText->setCaption({name.data(), name.size()}); line.mCharge->setVisible(false); switch (mDisplayMode) diff --git a/apps/openmw/mwgui/layout.cpp b/apps/openmw/mwgui/layout.cpp index 0f2af30a60..18c14f5eb9 100644 --- a/apps/openmw/mwgui/layout.cpp +++ b/apps/openmw/mwgui/layout.cpp @@ -52,12 +52,13 @@ namespace MWGui static_cast(pt)->setCaption(caption); } - void Layout::setTitle(const std::string& title) + void Layout::setTitle(std::string_view title) { MyGUI::Window* window = static_cast(mMainWidget); + MyGUI::UString uTitle{title.data(), title.size()}; - if (window->getCaption() != title) - window->setCaptionWithReplacing(title); + if (window->getCaption() != uTitle) + window->setCaptionWithReplacing(uTitle); } MyGUI::Widget* Layout::getWidget(std::string_view _name) diff --git a/apps/openmw/mwgui/layout.hpp b/apps/openmw/mwgui/layout.hpp index f0fd633ee2..ee17bacc75 100644 --- a/apps/openmw/mwgui/layout.hpp +++ b/apps/openmw/mwgui/layout.hpp @@ -64,7 +64,7 @@ namespace MWGui void setText(std::string_view name, const std::string& caption); // NOTE: this assume that mMainWidget is of type Window. - void setTitle(const std::string& title); + void setTitle(std::string_view title); MyGUI::Widget* mMainWidget; diff --git a/apps/openmw/mwgui/merchantrepair.cpp b/apps/openmw/mwgui/merchantrepair.cpp index 1542312efe..169dfe0de7 100644 --- a/apps/openmw/mwgui/merchantrepair.cpp +++ b/apps/openmw/mwgui/merchantrepair.cpp @@ -67,8 +67,8 @@ void MerchantRepair::setPtr(const MWWorld::Ptr &actor) int price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mActor, x, true); - std::string name = iter->getClass().getName(*iter) - + " - " + MyGUI::utility::toString(price) + std::string name{iter->getClass().getName(*iter)}; + name += " - " + MyGUI::utility::toString(price) + MWBase::Environment::get().getWorld()->getStore().get() .find("sgp")->mValue.getString(); diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index f7c46d3c83..7fe7cc2877 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -188,7 +188,8 @@ namespace MWGui { CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog(); std::string message = "#{sQuanityMenuMessage02}"; - std::string name = object.getClass().getName(object) + MWGui::ToolTips::getSoulString(object.getCellRef()); + std::string name{object.getClass().getName(object)}; + name += MWGui::ToolTips::getSoulString(object.getCellRef()); dialog->openCountDialog(name, message, count); dialog->eventOkClicked.clear(); dialog->eventOkClicked += MyGUI::newDelegate(this, &TradeWindow::sellItem); diff --git a/apps/openmw/mwscript/containerextensions.cpp b/apps/openmw/mwscript/containerextensions.cpp index becc82ef9c..7014d14265 100644 --- a/apps/openmw/mwscript/containerextensions.cpp +++ b/apps/openmw/mwscript/containerextensions.cpp @@ -160,7 +160,7 @@ namespace MWScript { // The two GMST entries below expand to strings informing the player of what, and how many of it has been added to their inventory std::string msgBox; - std::string itemName = itemPtr.getClass().getName(itemPtr); + std::string_view itemName = itemPtr.getClass().getName(itemPtr); if (count == 1) { msgBox = MyGUI::LanguageManager::getInstance().replaceTags("#{sNotifyMessage60}"); @@ -256,7 +256,7 @@ namespace MWScript } MWWorld::ContainerStore& store = ptr.getClass().getContainerStore (ptr); - std::string itemName; + std::string_view itemName; for (MWWorld::ConstContainerStoreIterator iter(store.cbegin()); iter != store.cend(); ++iter) { if (::Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), item)) diff --git a/apps/openmw/mwworld/actionharvest.cpp b/apps/openmw/mwworld/actionharvest.cpp index 582f582d3e..161d1f4e7e 100644 --- a/apps/openmw/mwworld/actionharvest.cpp +++ b/apps/openmw/mwworld/actionharvest.cpp @@ -43,7 +43,8 @@ namespace MWWorld MWBase::Environment::get().getMechanicsManager()->itemTaken(actor, *it, target, itemCount); actorStore.add(*it, itemCount, actor); store.remove(*it, itemCount, getTarget()); - takenMap[it->getClass().getName(*it)]+=itemCount; + std::string name{it->getClass().getName(*it)}; + takenMap[name]+=itemCount; } // Spawn a messagebox (only for items added to player's inventory) diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 95ec869559..ceba5ce86b 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -84,7 +84,7 @@ namespace MWWorld ///< Add reference into a cell for rendering (default implementation: don't render anything). virtual void insertObjectPhysics(const Ptr& ptr, const std::string& mesh, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) const; - virtual std::string getName (const ConstPtr& ptr) const = 0; + virtual std::string_view getName(const ConstPtr& ptr) const = 0; ///< \return name or ID; can return an empty string. virtual void adjustPosition(const MWWorld::Ptr& ptr, bool force) const; diff --git a/components/misc/strings/format.hpp b/components/misc/strings/format.hpp index 492518fe22..420a1161c4 100644 --- a/components/misc/strings/format.hpp +++ b/components/misc/strings/format.hpp @@ -16,10 +16,15 @@ namespace Misc::StringUtils template T argument(T value) noexcept { - static_assert(!std::is_same_v, "std::string_view is not supported"); return value; } + template + T const * argument(std::basic_string_view const & value) noexcept + { + return value.data(); + } + template T const * argument(std::basic_string const & value) noexcept { diff --git a/components/misc/utf8stream.hpp b/components/misc/utf8stream.hpp index 847d73ceb7..197d8ea4f0 100644 --- a/components/misc/utf8stream.hpp +++ b/components/misc/utf8stream.hpp @@ -122,14 +122,14 @@ public: return ch; } - static std::string lowerCaseUtf8(const std::string& str) + static std::string lowerCaseUtf8(std::string_view str) { if (str.empty()) - return str; + return std::string{str}; // Decode string as utf8 characters, convert to lower case and pack them to string std::string out; - Utf8Stream stream (str.c_str()); + Utf8Stream stream (str); while (!stream.eof ()) { UnicodeChar character = toLowerUtf8(stream.peek());