Merge branch 'esmtool_string_view' into 'master'

Use std::string_view for esmtool labels

See merge request OpenMW/openmw!2396
make_linux_ci_do_zoomies
psi29a 2 years ago
commit 20abe6dcf5

@ -15,11 +15,11 @@
#include <components/misc/strings/format.hpp>
std::string bodyPartLabel(int idx)
std::string_view bodyPartLabel(int idx)
{
if (idx >= 0 && idx <= 26)
{
static const char *bodyPartLabels[] = {
static constexpr std::string_view bodyPartLabels[] = {
"Head",
"Hair",
"Neck",
@ -54,11 +54,11 @@ std::string bodyPartLabel(int idx)
return "Invalid";
}
std::string meshPartLabel(int idx)
std::string_view meshPartLabel(int idx)
{
if (idx >= 0 && idx <= ESM::BodyPart::MP_Tail)
{
static const char *meshPartLabels[] = {
static constexpr std::string_view meshPartLabels[] = {
"Head",
"Hair",
"Neck",
@ -81,11 +81,11 @@ std::string meshPartLabel(int idx)
return "Invalid";
}
std::string meshTypeLabel(int idx)
std::string_view meshTypeLabel(int idx)
{
if (idx >= 0 && idx <= ESM::BodyPart::MT_Armor)
{
static const char *meshTypeLabels[] = {
static constexpr std::string_view meshTypeLabels[] = {
"Skin",
"Clothing",
"Armor",
@ -96,11 +96,11 @@ std::string meshTypeLabel(int idx)
return "Invalid";
}
std::string clothingTypeLabel(int idx)
std::string_view clothingTypeLabel(int idx)
{
if (idx >= 0 && idx <= 9)
{
static const char *clothingTypeLabels[] = {
static constexpr std::string_view clothingTypeLabels[] = {
"Pants",
"Shoes",
"Shirt",
@ -118,11 +118,11 @@ std::string clothingTypeLabel(int idx)
return "Invalid";
}
std::string armorTypeLabel(int idx)
std::string_view armorTypeLabel(int idx)
{
if (idx >= 0 && idx <= 10)
{
static const char *armorTypeLabels[] = {
static constexpr std::string_view armorTypeLabels[] = {
"Helmet",
"Cuirass",
"Left Pauldron",
@ -141,11 +141,11 @@ std::string armorTypeLabel(int idx)
return "Invalid";
}
std::string dialogTypeLabel(int idx)
std::string_view dialogTypeLabel(int idx)
{
if (idx >= 0 && idx <= 4)
{
static const char *dialogTypeLabels[] = {
static constexpr std::string_view dialogTypeLabels[] = {
"Topic",
"Voice",
"Greeting",
@ -160,11 +160,11 @@ std::string dialogTypeLabel(int idx)
return "Invalid";
}
std::string questStatusLabel(int idx)
std::string_view questStatusLabel(int idx)
{
if (idx >= 0 && idx <= 4)
{
static const char *questStatusLabels[] = {
static constexpr std::string_view questStatusLabels[] = {
"None",
"Name",
"Finished",
@ -177,11 +177,11 @@ std::string questStatusLabel(int idx)
return "Invalid";
}
std::string creatureTypeLabel(int idx)
std::string_view creatureTypeLabel(int idx)
{
if (idx >= 0 && idx <= 3)
{
static const char *creatureTypeLabels[] = {
static constexpr std::string_view creatureTypeLabels[] = {
"Creature",
"Daedra",
"Undead",
@ -193,11 +193,11 @@ std::string creatureTypeLabel(int idx)
return "Invalid";
}
std::string soundTypeLabel(int idx)
std::string_view soundTypeLabel(int idx)
{
if (idx >= 0 && idx <= 7)
{
static const char *soundTypeLabels[] = {
static constexpr std::string_view soundTypeLabels[] = {
"Left Foot",
"Right Foot",
"Swim Left",
@ -213,11 +213,11 @@ std::string soundTypeLabel(int idx)
return "Invalid";
}
std::string weaponTypeLabel(int idx)
std::string_view weaponTypeLabel(int idx)
{
if (idx >= 0 && idx <= 13)
{
static const char *weaponTypeLabels[] = {
static constexpr std::string_view weaponTypeLabels[] = {
"Short Blade One Hand",
"Long Blade One Hand",
"Long Blade Two Hand",
@ -239,7 +239,7 @@ std::string weaponTypeLabel(int idx)
return "Invalid";
}
std::string aiTypeLabel(int type)
std::string_view aiTypeLabel(int type)
{
if (type == ESM::AI_Wander) return "Wander";
else if (type == ESM::AI_Travel) return "Travel";
@ -249,11 +249,11 @@ std::string aiTypeLabel(int type)
else return "Invalid";
}
std::string magicEffectLabel(int idx)
std::string_view magicEffectLabel(int idx)
{
if (idx >= 0 && idx <= 142)
{
const char* magicEffectLabels [] = {
static constexpr std::string_view magicEffectLabels [] = {
"Water Breathing",
"Swift Swim",
"Water Walking",
@ -404,11 +404,11 @@ std::string magicEffectLabel(int idx)
return "Invalid";
}
std::string attributeLabel(int idx)
std::string_view attributeLabel(int idx)
{
if (idx >= 0 && idx <= 7)
{
const char* attributeLabels [] = {
static constexpr std::string_view attributeLabels [] = {
"Strength",
"Intelligence",
"Willpower",
@ -424,11 +424,11 @@ std::string attributeLabel(int idx)
return "Invalid";
}
std::string spellTypeLabel(int idx)
std::string_view spellTypeLabel(int idx)
{
if (idx >= 0 && idx <= 5)
{
const char* spellTypeLabels [] = {
static constexpr std::string_view spellTypeLabels [] = {
"Spells",
"Abilities",
"Blight Disease",
@ -442,11 +442,11 @@ std::string spellTypeLabel(int idx)
return "Invalid";
}
std::string specializationLabel(int idx)
std::string_view specializationLabel(int idx)
{
if (idx >= 0 && idx <= 2)
{
const char* specializationLabels [] = {
static constexpr std::string_view specializationLabels [] = {
"Combat",
"Magic",
"Stealth",
@ -457,11 +457,11 @@ std::string specializationLabel(int idx)
return "Invalid";
}
std::string skillLabel(int idx)
std::string_view skillLabel(int idx)
{
if (idx >= 0 && idx <= 26)
{
const char* skillLabels [] = {
static constexpr std::string_view skillLabels [] = {
"Block",
"Armorer",
"Medium Armor",
@ -496,11 +496,11 @@ std::string skillLabel(int idx)
return "Invalid";
}
std::string apparatusTypeLabel(int idx)
std::string_view apparatusTypeLabel(int idx)
{
if (idx >= 0 && idx <= 3)
{
const char* apparatusTypeLabels [] = {
static constexpr std::string_view apparatusTypeLabels [] = {
"Mortar",
"Alembic",
"Calcinator",
@ -512,11 +512,11 @@ std::string apparatusTypeLabel(int idx)
return "Invalid";
}
std::string rangeTypeLabel(int idx)
std::string_view rangeTypeLabel(int idx)
{
if (idx >= 0 && idx <= 2)
{
const char* rangeTypeLabels [] = {
static constexpr std::string_view rangeTypeLabels [] = {
"Self",
"Touch",
"Target",
@ -527,11 +527,11 @@ std::string rangeTypeLabel(int idx)
return "Invalid";
}
std::string schoolLabel(int idx)
std::string_view schoolLabel(int idx)
{
if (idx >= 0 && idx <= 5)
{
const char* schoolLabels [] = {
static constexpr std::string_view schoolLabels [] = {
"Alteration",
"Conjuration",
"Destruction",
@ -545,11 +545,11 @@ std::string schoolLabel(int idx)
return "Invalid";
}
std::string enchantTypeLabel(int idx)
std::string_view enchantTypeLabel(int idx)
{
if (idx >= 0 && idx <= 3)
{
const char* enchantTypeLabels [] = {
static constexpr std::string_view enchantTypeLabels [] = {
"Cast Once",
"Cast When Strikes",
"Cast When Used",
@ -561,11 +561,11 @@ std::string enchantTypeLabel(int idx)
return "Invalid";
}
std::string ruleFunction(int idx)
std::string_view ruleFunction(int idx)
{
if (idx >= 0 && idx <= 72)
{
std::string ruleFunctions[] = {
static constexpr std::string_view ruleFunctions[] = {
"Reaction Low",
"Reaction High",
"Rank Requirement",

@ -3,25 +3,25 @@
#include <string>
std::string bodyPartLabel(int idx);
std::string meshPartLabel(int idx);
std::string meshTypeLabel(int idx);
std::string clothingTypeLabel(int idx);
std::string armorTypeLabel(int idx);
std::string dialogTypeLabel(int idx);
std::string questStatusLabel(int idx);
std::string creatureTypeLabel(int idx);
std::string soundTypeLabel(int idx);
std::string weaponTypeLabel(int idx);
std::string_view bodyPartLabel(int idx);
std::string_view meshPartLabel(int idx);
std::string_view meshTypeLabel(int idx);
std::string_view clothingTypeLabel(int idx);
std::string_view armorTypeLabel(int idx);
std::string_view dialogTypeLabel(int idx);
std::string_view questStatusLabel(int idx);
std::string_view creatureTypeLabel(int idx);
std::string_view soundTypeLabel(int idx);
std::string_view weaponTypeLabel(int idx);
// This function's a bit different because the types are record types,
// not consecutive values.
std::string aiTypeLabel(int type);
std::string_view aiTypeLabel(int type);
// This one's also a bit different, because it enumerates dialog
// select rule functions, not types. Structurally, it still converts
// indexes to strings for display.
std::string ruleFunction(int idx);
std::string_view ruleFunction(int idx);
// The labels below here can all be loaded from GMSTs, but are not
// currently because among other things, that requires loading the
@ -32,15 +32,15 @@ std::string ruleFunction(int idx);
// and the indexes for referencing the types in other records in the
// database. Then a single label function could work for all types.
std::string magicEffectLabel(int idx);
std::string attributeLabel(int idx);
std::string spellTypeLabel(int idx);
std::string specializationLabel(int idx);
std::string skillLabel(int idx);
std::string apparatusTypeLabel(int idx);
std::string rangeTypeLabel(int idx);
std::string schoolLabel(int idx);
std::string enchantTypeLabel(int idx);
std::string_view magicEffectLabel(int idx);
std::string_view attributeLabel(int idx);
std::string_view spellTypeLabel(int idx);
std::string_view specializationLabel(int idx);
std::string_view skillLabel(int idx);
std::string_view apparatusTypeLabel(int idx);
std::string_view rangeTypeLabel(int idx);
std::string_view schoolLabel(int idx);
std::string_view enchantTypeLabel(int idx);
// The are the flag functions that convert a bitmask into a list of
// human readble strings representing the set bits.

@ -73,7 +73,7 @@ std::string ruleString(const ESM::DialInfo::SelectStruct& ss)
{
case '1':
type_str = "Function";
func_str = ruleFunction(func);
func_str = std::string(ruleFunction(func));
break;
case '2':
if (indicator == 's') type_str = "Global short";

Loading…
Cancel
Save