diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index e7e29a58b4..e0b88bba12 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -519,7 +519,7 @@ namespace MWDialogue void DialogueManager::addChoice(std::string_view text, int choice) { mIsInChoice = true; - mChoices.emplace_back(std::string{text.begin(), text.end()}, choice); + mChoices.emplace_back(text, choice); } const std::vector >& DialogueManager::getChoices() diff --git a/apps/openmw/mwscript/aiextensions.cpp b/apps/openmw/mwscript/aiextensions.cpp index 3b6b47bc80..519af584f0 100644 --- a/apps/openmw/mwscript/aiextensions.cpp +++ b/apps/openmw/mwscript/aiextensions.cpp @@ -168,7 +168,7 @@ namespace MWScript if (cellID.empty()) return; - if (!MWBase::Environment::get().getWorld()->getStore().get().search({cellID.begin(), cellID.end()})) + if (!MWBase::Environment::get().getWorld()->getStore().get().search(std::string{cellID})) return; MWMechanics::AiEscort escortPackage(actorID, cellID, static_cast(duration), x, y, z, repeat); diff --git a/apps/openmw/mwscript/animationextensions.cpp b/apps/openmw/mwscript/animationextensions.cpp index a53b08d516..12fe5256be 100644 --- a/apps/openmw/mwscript/animationextensions.cpp +++ b/apps/openmw/mwscript/animationextensions.cpp @@ -58,7 +58,7 @@ namespace MWScript throw std::runtime_error ("animation mode out of range"); } - MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(ptr, {group.begin(), group.end()}, mode, std::numeric_limits::max(), true); + MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(ptr, std::string{group}, mode, std::numeric_limits::max(), true); } }; @@ -94,7 +94,7 @@ namespace MWScript throw std::runtime_error ("animation mode out of range"); } - MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(ptr, {group.begin(), group.end()}, mode, loops + 1, true); + MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(ptr, std::string{group}, mode, loops + 1, true); } }; diff --git a/apps/openmw/mwscript/cellextensions.cpp b/apps/openmw/mwscript/cellextensions.cpp index 2e11631a28..0419d37962 100644 --- a/apps/openmw/mwscript/cellextensions.cpp +++ b/apps/openmw/mwscript/cellextensions.cpp @@ -87,8 +87,7 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string_view cellView = runtime.getStringLiteral(runtime[0].mInteger); - std::string cell{cellView.begin(), cellView.end()}; + std::string cell{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); ESM::Position pos; diff --git a/apps/openmw/mwscript/containerextensions.cpp b/apps/openmw/mwscript/containerextensions.cpp index 78919d4b48..11e9095e2c 100644 --- a/apps/openmw/mwscript/containerextensions.cpp +++ b/apps/openmw/mwscript/containerextensions.cpp @@ -116,7 +116,7 @@ namespace MWScript // Explicit calls to non-unique actors affect the base record if(!R::implicit && ptr.getClass().isActor() && MWBase::Environment::get().getWorld()->getStore().getRefCount(ptr.getCellRef().getRefId()) > 1) { - ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), {item.begin(), item.end()}, count); + ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), std::string{item}, count); return; } @@ -124,7 +124,7 @@ namespace MWScript if(ptr.getClass().getType() == ESM::Container::sRecordId && (!ptr.getRefData().getCustomData() || !ptr.getClass().getContainerStore(ptr).isResolved())) { - ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), {item.begin(), item.end()}, count); + ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), std::string{item}, count); const ESM::Container* baseRecord = MWBase::Environment::get().getWorld()->getStore().get().find(ptr.getCellRef().getRefId()); const auto& ptrs = MWBase::Environment::get().getWorld()->getAll(ptr.getCellRef().getRefId()); for(const auto& container : ptrs) @@ -229,14 +229,14 @@ namespace MWScript // Explicit calls to non-unique actors affect the base record if(!R::implicit && ptr.getClass().isActor() && MWBase::Environment::get().getWorld()->getStore().getRefCount(ptr.getCellRef().getRefId()) > 1) { - ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), {item.begin(), item.end()}, -count); + ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), std::string{item}, -count); return; } // Calls to unresolved containers affect the base record instead else if(ptr.getClass().getType() == ESM::Container::sRecordId && (!ptr.getRefData().getCustomData() || !ptr.getClass().getContainerStore(ptr).isResolved())) { - ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), {item.begin(), item.end()}, -count); + ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), std::string{item}, -count); const ESM::Container* baseRecord = MWBase::Environment::get().getWorld()->getStore().get().find(ptr.getCellRef().getRefId()); const auto& ptrs = MWBase::Environment::get().getWorld()->getAll(ptr.getCellRef().getRefId()); for(const auto& container : ptrs) diff --git a/apps/openmw/mwscript/dialogueextensions.cpp b/apps/openmw/mwscript/dialogueextensions.cpp index e03aa4cb1c..f06ee022e2 100644 --- a/apps/openmw/mwscript/dialogueextensions.cpp +++ b/apps/openmw/mwscript/dialogueextensions.cpp @@ -34,8 +34,7 @@ namespace MWScript if (ptr.isEmpty()) ptr = MWBase::Environment::get().getWorld()->getPlayerPtr(); - std::string_view questView = runtime.getStringLiteral(runtime[0].mInteger); - std::string quest{questView.begin(), questView.end()}; + std::string quest{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); Interpreter::Type_Integer index = runtime[0].mInteger; @@ -60,13 +59,13 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string_view quest = runtime.getStringLiteral(runtime[0].mInteger); + std::string quest{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); Interpreter::Type_Integer index = runtime[0].mInteger; runtime.pop(); - MWBase::Environment::get().getJournal()->setJournalIndex({quest.begin(), quest.end()}, index); + MWBase::Environment::get().getJournal()->setJournalIndex (quest, index); } }; @@ -76,10 +75,10 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string_view quest = runtime.getStringLiteral(runtime[0].mInteger); + std::string quest{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); - int index = MWBase::Environment::get().getJournal()->getJournalIndex({quest.begin(), quest.end()}); + int index = MWBase::Environment::get().getJournal()->getJournalIndex (quest); runtime.push (index); diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 341bb0d6dd..d620882dde 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -60,7 +60,7 @@ namespace } ESM::LevelledListBase::LevelItem item; - item.mId = {itemId.begin(), itemId.end()}; + item.mId = std::string{itemId}; item.mLevel = level; list->mList.push_back(item); } @@ -206,13 +206,13 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string_view name = runtime.getStringLiteral(runtime[0].mInteger); + std::string name{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); bool allowSkipping = runtime[0].mInteger != 0; runtime.pop(); - MWBase::Environment::get().getWindowManager()->playVideo({name.begin(), name.end()}, allowSkipping); + MWBase::Environment::get().getWindowManager()->playVideo (name, allowSkipping); } }; @@ -560,7 +560,7 @@ namespace MWScript char *end; long key = strtol(effect.data(), &end, 10); if(key < 0 || key > 32767 || *end != '\0') - key = ESM::MagicEffect::effectStringToId({effect.begin(), effect.end()}); + key = ESM::MagicEffect::effectStringToId({effect}); const MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); @@ -587,8 +587,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view creatureView = runtime.getStringLiteral(runtime[0].mInteger); - std::string creature{creatureView.begin(), creatureView.end()}; + std::string creature{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); std::string_view gem = runtime.getStringLiteral(runtime[0].mInteger); @@ -600,7 +599,7 @@ namespace MWScript const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); store.get().find(creature); // This line throws an exception if it can't find the creature - MWWorld::Ptr item = *ptr.getClass().getContainerStore(ptr).add({gem.begin(), gem.end()}, 1, ptr); + MWWorld::Ptr item = *ptr.getClass().getContainerStore(ptr).add(gem, 1, ptr); // Set the soul on just one of the gems, not the whole stack item.getContainerStore()->unstack(item, ptr); @@ -1214,16 +1213,16 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view spellId = runtime.getStringLiteral(runtime[0].mInteger); + std::string spellId{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); std::string targetId = ::Misc::StringUtils::lowerCase(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); - const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().search({spellId.begin(), spellId.end()}); + const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().search(spellId); if (!spell) { - runtime.getContext().report("spellcasting failed: cannot find spell \""+std::string{spellId.begin(), spellId.end()}+"\""); + runtime.getContext().report("spellcasting failed: cannot find spell \""+spellId+"\""); return; } @@ -1263,13 +1262,13 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view spellId = runtime.getStringLiteral(runtime[0].mInteger); + std::string spellId{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); - const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().search({spellId.begin(), spellId.end()}); + const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().search(spellId); if (!spell) { - runtime.getContext().report("spellcasting failed: cannot find spell \""+std::string{spellId.begin(), spellId.end()}+"\""); + runtime.getContext().report("spellcasting failed: cannot find spell \""+spellId+"\""); return; } @@ -1426,14 +1425,14 @@ namespace MWScript public: void execute(Interpreter::Runtime &runtime) override { - std::string_view levId = runtime.getStringLiteral(runtime[0].mInteger); + std::string levId{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); std::string_view creatureId = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); int level = runtime[0].mInteger; runtime.pop(); - ESM::CreatureLevList listCopy = *MWBase::Environment::get().getWorld()->getStore().get().find({levId.begin(), levId.end()}); + ESM::CreatureLevList listCopy = *MWBase::Environment::get().getWorld()->getStore().get().find(levId); addToLevList(&listCopy, creatureId, level); MWBase::Environment::get().getWorld()->createOverrideRecord(listCopy); } @@ -1444,14 +1443,14 @@ namespace MWScript public: void execute(Interpreter::Runtime &runtime) override { - std::string_view levId = runtime.getStringLiteral(runtime[0].mInteger); + std::string levId{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); std::string_view creatureId = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); int level = runtime[0].mInteger; runtime.pop(); - ESM::CreatureLevList listCopy = *MWBase::Environment::get().getWorld()->getStore().get().find({levId.begin(), levId.end()}); + ESM::CreatureLevList listCopy = *MWBase::Environment::get().getWorld()->getStore().get().find(levId); removeFromLevList(&listCopy, creatureId, level); MWBase::Environment::get().getWorld()->createOverrideRecord(listCopy); } @@ -1462,14 +1461,14 @@ namespace MWScript public: void execute(Interpreter::Runtime &runtime) override { - std::string_view levId = runtime.getStringLiteral(runtime[0].mInteger); + std::string levId{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); std::string_view itemId = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); int level = runtime[0].mInteger; runtime.pop(); - ESM::ItemLevList listCopy = *MWBase::Environment::get().getWorld()->getStore().get().find({levId.begin(), levId.end()}); + ESM::ItemLevList listCopy = *MWBase::Environment::get().getWorld()->getStore().get().find(levId); addToLevList(&listCopy, itemId, level); MWBase::Environment::get().getWorld()->createOverrideRecord(listCopy); } @@ -1480,14 +1479,14 @@ namespace MWScript public: void execute(Interpreter::Runtime &runtime) override { - std::string_view levId = runtime.getStringLiteral(runtime[0].mInteger); + std::string levId{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); std::string_view itemId = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); int level = runtime[0].mInteger; runtime.pop(); - ESM::ItemLevList listCopy = *MWBase::Environment::get().getWorld()->getStore().get().find({levId.begin(), levId.end()}); + ESM::ItemLevList listCopy = *MWBase::Environment::get().getWorld()->getStore().get().find(levId); removeFromLevList(&listCopy, itemId, level); MWBase::Environment::get().getWorld()->createOverrideRecord(listCopy); } diff --git a/apps/openmw/mwscript/skyextensions.cpp b/apps/openmw/mwscript/skyextensions.cpp index b7b79f8ed4..f81645b280 100644 --- a/apps/openmw/mwscript/skyextensions.cpp +++ b/apps/openmw/mwscript/skyextensions.cpp @@ -87,8 +87,7 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string_view regionView = runtime.getStringLiteral(runtime[0].mInteger); - std::string region{regionView.begin(), regionView.end()}; + std::string region{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); Interpreter::Type_Integer id = runtime[0].mInteger; @@ -108,8 +107,7 @@ namespace MWScript void execute (Interpreter::Runtime& runtime, unsigned int arg0) override { - std::string_view regionView = runtime.getStringLiteral(runtime[0].mInteger); - std::string region{regionView.begin(), regionView.end()}; + std::string region{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); std::vector chances; diff --git a/apps/openmw/mwscript/soundextensions.cpp b/apps/openmw/mwscript/soundextensions.cpp index 42bb59d1ec..1e0ad12946 100644 --- a/apps/openmw/mwscript/soundextensions.cpp +++ b/apps/openmw/mwscript/soundextensions.cpp @@ -33,16 +33,16 @@ namespace MWScript MWScript::InterpreterContext& context = static_cast (runtime.getContext()); - std::string_view file = runtime.getStringLiteral(runtime[0].mInteger); + std::string file{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); - std::string_view text = runtime.getStringLiteral(runtime[0].mInteger); + std::string text{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); - MWBase::Environment::get().getSoundManager()->say(ptr, {file.begin(), file.end()}); + MWBase::Environment::get().getSoundManager()->say (ptr, file); if (MWBase::Environment::get().getWindowManager ()->getSubtitlesEnabled()) - context.messageBox({text.begin(), text.end()}); + context.messageBox (text); } }; @@ -65,10 +65,10 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string_view sound = runtime.getStringLiteral(runtime[0].mInteger); + std::string sound{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); - MWBase::Environment::get().getSoundManager()->streamMusic({sound.begin(), sound.end()}); + MWBase::Environment::get().getSoundManager()->streamMusic (sound); } }; diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 1df763cf8e..4be2b9b8f4 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -447,10 +447,10 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view id = runtime.getStringLiteral(runtime[0].mInteger); + std::string id{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); - const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().find({id.begin(), id.end()}); + const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().find (id); MWMechanics::CreatureStats& creatureStats = ptr.getClass().getCreatureStats(ptr); creatureStats.getSpells().add(spell); @@ -474,11 +474,11 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view id = runtime.getStringLiteral(runtime[0].mInteger); + std::string id{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); MWMechanics::CreatureStats& creatureStats = ptr.getClass().getCreatureStats(ptr); - creatureStats.getSpells().remove({id.begin(), id.end()}); + creatureStats.getSpells().remove (id); MWBase::WindowManager *wm = MWBase::Environment::get().getWindowManager(); @@ -532,12 +532,12 @@ namespace MWScript MWWorld::Ptr ptr = R()(runtime); - std::string_view id = runtime.getStringLiteral(runtime[0].mInteger); + std::string id{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); Interpreter::Type_Integer value = 0; - if (ptr.getClass().isActor() && ptr.getClass().getCreatureStats(ptr).getSpells().hasSpell({id.begin(), id.end()})) + if (ptr.getClass().isActor() && ptr.getClass().getCreatureStats(ptr).getSpells().hasSpell(id)) value = 1; runtime.push (value); @@ -748,8 +748,8 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string_view id = runtime.getStringLiteral(runtime[0].mInteger); - runtime[0].mInteger = MWBase::Environment::get().getMechanicsManager()->countDeaths({id.begin(), id.end()}); + std::string id{runtime.getStringLiteral(runtime[0].mInteger)}; + runtime[0].mInteger = MWBase::Environment::get().getMechanicsManager()->countDeaths (id); } }; diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index 8617d7eedd..dbcb1087f9 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -74,8 +74,7 @@ namespace MWScript const MWWorld::Ptr to = MWBase::Environment::get().getWorld()->searchPtr(name, false); if (to.isEmpty()) { - std::string error = "Failed to find an instance of object '"; - error += name; error += "'"; + std::string error = "Failed to find an instance of object '" + std::string(name) + "'"; runtime.getContext().report(error); Log(Debug::Error) << error; runtime.push(0.f); @@ -381,8 +380,7 @@ namespace MWScript runtime.pop(); Interpreter::Type_Float zRot = runtime[0].mFloat; runtime.pop(); - std::string_view cellIDView = runtime.getStringLiteral(runtime[0].mInteger); - std::string cellID{cellIDView.begin(), cellIDView.end()}; + std::string cellID{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); if (ptr.getContainerStore()) @@ -499,8 +497,7 @@ namespace MWScript { std::string_view itemID = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); - std::string_view cellIDView = runtime.getStringLiteral(runtime[0].mInteger); - std::string cellID{cellIDView.begin(), cellIDView.end()}; + std::string cellID{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); Interpreter::Type_Float x = runtime[0].mFloat; diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index aee110286e..14a19c482c 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -278,7 +278,7 @@ bool MWWorld::ContainerStore::stacks(const ConstPtr& ptr1, const ConstPtr& ptr2) && cls2.getItemHealth(ptr2) == cls2.getItemMaxHealth(ptr2))); } -MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add(const std::string &id, int count, const Ptr &actorPtr) +MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add(std::string_view id, int count, const Ptr &actorPtr) { MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), id, count); return add(ref.getPtr(), count, actorPtr); diff --git a/apps/openmw/mwworld/containerstore.hpp b/apps/openmw/mwworld/containerstore.hpp index 38ae933581..74e46ea5f4 100644 --- a/apps/openmw/mwworld/containerstore.hpp +++ b/apps/openmw/mwworld/containerstore.hpp @@ -175,7 +175,7 @@ namespace MWWorld /// /// @return if stacking happened, return iterator to the item that was stacked against, otherwise iterator to the newly inserted item. - ContainerStoreIterator add(const std::string& id, int count, const Ptr& actorPtr); + ContainerStoreIterator add(std::string_view id, int count, const Ptr& actorPtr); ///< Utility to construct a ManualRef and call add(ptr, count, actorPtr, true) int remove(std::string_view itemId, int count, const Ptr& actor, bool equipReplacement = 0, bool resolve = true); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 54dc94d0b0..a4405ae75a 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -767,8 +767,7 @@ namespace MWWorld Ptr ret = searchPtr(name, activeOnly); if (!ret.isEmpty()) return ret; - std::string error = "failed to find an instance of object '"; - error += name; error += "'"; + std::string error = "failed to find an instance of object '" + std::string(name) + error; if (activeOnly) error += " in active cells"; throw std::runtime_error(error); diff --git a/apps/openmw_test_suite/mwscript/test_utils.hpp b/apps/openmw_test_suite/mwscript/test_utils.hpp index e0bf8d0440..15f2fae661 100644 --- a/apps/openmw_test_suite/mwscript/test_utils.hpp +++ b/apps/openmw_test_suite/mwscript/test_utils.hpp @@ -128,11 +128,11 @@ namespace float getFloat(std::string_view name) const { return getGlobal(name, mFloats); }; - void setShort(std::string_view name, int value) { mShorts[{name.begin(), name.end()}] = value; }; + void setShort(std::string_view name, int value) { mShorts[std::string(name)] = value; }; - void setLong(std::string_view name, int value) { mLongs[{name.begin(), name.end()}] = value; }; + void setLong(std::string_view name, int value) { mLongs[std::string(name)] = value; }; - void setFloat(std::string_view name, float value) { mFloats[{name.begin(), name.end()}] = value; }; + void setFloat(std::string_view name, float value) { mFloats[std::string(name)] = value; }; }; class TestInterpreterContext : public Interpreter::Context @@ -224,11 +224,11 @@ namespace return {}; }; - void setMemberShort(std::string_view id, std::string_view name, int value, bool global) override { mMembers[{id.begin(), id.end()}].setShort(name, value); }; + void setMemberShort(std::string_view id, std::string_view name, int value, bool global) override { mMembers[std::string(id)].setShort(name, value); }; - void setMemberLong(std::string_view id, std::string_view name, int value, bool global) override { mMembers[{id.begin(), id.end()}].setLong(name, value); }; + void setMemberLong(std::string_view id, std::string_view name, int value, bool global) override { mMembers[std::string(id)].setLong(name, value); }; - void setMemberFloat(std::string_view id, std::string_view name, float value, bool global) override { mMembers[{id.begin(), id.end()}].setFloat(name, value); }; + void setMemberFloat(std::string_view id, std::string_view name, float value, bool global) override { mMembers[std::string(id)].setFloat(name, value); }; }; struct CompiledScript diff --git a/components/esm3/loadmgef.cpp b/components/esm3/loadmgef.cpp index 9707f2f255..5fb88a3606 100644 --- a/components/esm3/loadmgef.cpp +++ b/components/esm3/loadmgef.cpp @@ -533,10 +533,10 @@ const std::string &MagicEffect::effectIdToString(short effectID) } class FindSecond { - const std::string &mName; + std::string_view mName; public: - FindSecond(const std::string &name) : mName(name) { } + FindSecond(std::string_view name) : mName(name) { } bool operator()(const std::pair &item) const { @@ -546,13 +546,13 @@ public: } }; -short MagicEffect::effectStringToId(const std::string &effect) +short MagicEffect::effectStringToId(std::string_view effect) { std::map::const_iterator name; name = std::find_if(sNames.begin(), sNames.end(), FindSecond(effect)); if(name == sNames.end()) - throw std::runtime_error(std::string("Unimplemented effect ")+effect); + throw std::runtime_error("Unimplemented effect " + std::string(effect)); return name->first; } diff --git a/components/esm3/loadmgef.hpp b/components/esm3/loadmgef.hpp index 64d89dab39..b9151f5d33 100644 --- a/components/esm3/loadmgef.hpp +++ b/components/esm3/loadmgef.hpp @@ -2,6 +2,7 @@ #define OPENMW_ESM_MGEF_H #include +#include #include namespace ESM @@ -70,7 +71,7 @@ struct MagicEffect static const std::map sNames; static const std::string &effectIdToString(short effectID); - static short effectStringToId(const std::string &effect); + static short effectStringToId(std::string_view effect); /// Returns the effect that provides resistance against \a effect (or -1 if there's none) static short getResistanceEffect(short effect); diff --git a/components/interpreter/miscopcodes.hpp b/components/interpreter/miscopcodes.hpp index 1a35dda0ce..32b4df2e47 100644 --- a/components/interpreter/miscopcodes.hpp +++ b/components/interpreter/miscopcodes.hpp @@ -137,8 +137,7 @@ namespace Interpreter { index = runtime[0].mInteger; runtime.pop(); - std::string_view button = runtime.getStringLiteral(index); - buttons.emplace_back(button.begin(), button.end()); + buttons.emplace_back(runtime.getStringLiteral(index)); } std::reverse (buttons.begin(), buttons.end());