From a7ba54c361d8e50b4bd17f5e06860925e185bbfd Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sun, 10 Aug 2025 12:03:34 +0200 Subject: [PATCH] Use std::format in esmtool --- apps/esmtool/labels.cpp | 36 ++++++++++++++++----------------- apps/esmtool/record.cpp | 44 ++++++++++++++++++++--------------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/apps/esmtool/labels.cpp b/apps/esmtool/labels.cpp index 3d64563923..5bcd47da45 100644 --- a/apps/esmtool/labels.cpp +++ b/apps/esmtool/labels.cpp @@ -1,5 +1,7 @@ #include "labels.hpp" +#include + #include #include #include @@ -16,8 +18,6 @@ #include #include -#include - std::string_view bodyPartLabel(int idx) { if (idx >= 0 && idx <= 26) @@ -675,7 +675,7 @@ std::string bodyPartFlags(int flags) int unused = (0xFFFFFFFF ^ (ESM::BodyPart::BPF_Female | ESM::BodyPart::BPF_NotPlayable)); if (flags & unused) properties += "Invalid "; - properties += Misc::StringUtils::format("(0x%08X)", flags); + properties += std::format("(0x{:08X})", flags); return properties; } @@ -699,7 +699,7 @@ std::string cellFlags(int flags) ^ (ESM::Cell::HasWater | ESM::Cell::Interior | ESM::Cell::NoSleep | ESM::Cell::QuasiEx | 0x00000040)); if (flags & unused) properties += "Invalid "; - properties += Misc::StringUtils::format("(0x%08X)", flags); + properties += std::format("(0x{:08X})", flags); return properties; } @@ -717,7 +717,7 @@ std::string containerFlags(int flags) int unused = (0xFFFFFFFF ^ (ESM::Container::Unknown | ESM::Container::Organic | ESM::Container::Respawn)); if (flags & unused) properties += "Invalid "; - properties += Misc::StringUtils::format("(0x%08X)", flags); + properties += std::format("(0x{:08X})", flags); return properties; } @@ -747,7 +747,7 @@ std::string creatureFlags(int flags) | ESM::Creature::Bipedal | ESM::Creature::Respawn | ESM::Creature::Weapon | ESM::Creature::Essential)); if (flags & unused) properties += "Invalid "; - properties += Misc::StringUtils::format("(0x%02X)", flags); + properties += std::format("(0x{:02X})", flags); return properties; } @@ -760,7 +760,7 @@ std::string enchantmentFlags(int flags) properties += "Autocalc "; if (flags & (0xFFFFFFFF ^ ESM::Enchantment::Autocalc)) properties += "Invalid "; - properties += Misc::StringUtils::format("(0x%08X)", flags); + properties += std::format("(0x{:08X})", flags); return properties; } @@ -778,7 +778,7 @@ std::string landFlags(std::uint32_t flags) int unused = 0xFFFFFFFF ^ (ESM::Land::Flag_HeightsNormals | ESM::Land::Flag_Colors | ESM::Land::Flag_Textures); if (flags & unused) properties += "Invalid "; - properties += Misc::StringUtils::format("(0x%08X)", flags); + properties += std::format("(0x{:08X})", flags); return properties; } @@ -794,7 +794,7 @@ std::string itemListFlags(int flags) int unused = (0xFFFFFFFF ^ (ESM::ItemLevList::AllLevels | ESM::ItemLevList::Each)); if (flags & unused) properties += "Invalid "; - properties += Misc::StringUtils::format("(0x%08X)", flags); + properties += std::format("(0x{:08X})", flags); return properties; } @@ -808,7 +808,7 @@ std::string creatureListFlags(int flags) int unused = (0xFFFFFFFF ^ ESM::CreatureLevList::AllLevels); if (flags & unused) properties += "Invalid "; - properties += Misc::StringUtils::format("(0x%08X)", flags); + properties += std::format("(0x{:08X})", flags); return properties; } @@ -840,7 +840,7 @@ std::string lightFlags(int flags) | ESM::Light::Pulse | ESM::Light::PulseSlow | ESM::Light::Negative | ESM::Light::OffDefault)); if (flags & unused) properties += "Invalid "; - properties += Misc::StringUtils::format("(0x%08X)", flags); + properties += std::format("(0x{:08X})", flags); return properties; } @@ -888,7 +888,7 @@ std::string magicEffectFlags(int flags) if (flags & 0xFFFC0000) properties += "Invalid "; - properties += Misc::StringUtils::format("(0x%08X)", flags); + properties += std::format("(0x{:08X})", flags); return properties; } @@ -913,7 +913,7 @@ std::string npcFlags(int flags) = (0xFF ^ (ESM::NPC::Base | ESM::NPC::Autocalc | ESM::NPC::Female | ESM::NPC::Respawn | ESM::NPC::Essential)); if (flags & unused) properties += "Invalid "; - properties += Misc::StringUtils::format("(0x%02X)", flags); + properties += std::format("(0x{:02X})", flags); return properties; } @@ -930,7 +930,7 @@ std::string raceFlags(int flags) int unused = (0xFFFFFFFF ^ (ESM::Race::Playable | ESM::Race::Beast)); if (flags & unused) properties += "Invalid "; - properties += Misc::StringUtils::format("(0x%08X)", flags); + properties += std::format("(0x{:08X})", flags); return properties; } @@ -948,7 +948,7 @@ std::string spellFlags(int flags) int unused = (0xFFFFFFFF ^ (ESM::Spell::F_Autocalc | ESM::Spell::F_PCStart | ESM::Spell::F_Always)); if (flags & unused) properties += "Invalid "; - properties += Misc::StringUtils::format("(0x%08X)", flags); + properties += std::format("(0x{:08X})", flags); return properties; } @@ -967,7 +967,7 @@ std::string weaponFlags(int flags) int unused = (0xFFFFFFFF ^ (ESM::Weapon::Magical | ESM::Weapon::Silver)); if (flags & unused) properties += "Invalid "; - properties += Misc::StringUtils::format("(0x%08X)", flags); + properties += std::format("(0x{:08X})", flags); return properties; } @@ -987,7 +987,7 @@ std::string recordFlags(uint32_t flags) int unused = ~(ESM::FLAG_Deleted | ESM::FLAG_Persistent | ESM::FLAG_Ignored | ESM::FLAG_Blocked); if (flags & unused) properties += "Invalid "; - properties += Misc::StringUtils::format("(0x%08X)", flags); + properties += std::format("(0x{:08X})", flags); return properties; } @@ -1000,6 +1000,6 @@ std::string potionFlags(int flags) properties += "Autocalc "; if (flags & (0xFFFFFFFF ^ ESM::Enchantment::Autocalc)) properties += "Invalid "; - properties += Misc::StringUtils::format("(0x%08X)", flags); + properties += std::format("(0x{:08X})", flags); return properties; } diff --git a/apps/esmtool/record.cpp b/apps/esmtool/record.cpp index 8bb9a138b1..8108199208 100644 --- a/apps/esmtool/record.cpp +++ b/apps/esmtool/record.cpp @@ -1,6 +1,7 @@ #include "record.hpp" #include "labels.hpp" +#include #include #include #include @@ -8,14 +9,13 @@ #include #include #include -#include namespace { void printAIPackage(const ESM::AIPackage& p) { - std::cout << " AI Type: " << aiTypeLabel(p.mType) << " (" << Misc::StringUtils::format("0x%08X", p.mType) + std::cout << " AI Type: " << aiTypeLabel(p.mType) << " (" << std::format("0x{:08X}", std::uint32_t(p.mType)) << ")" << std::endl; if (p.mType == ESM::AI_Wander) { @@ -51,7 +51,7 @@ namespace } else { - std::cout << " BadPackage: " << Misc::StringUtils::format("0x%08X", p.mType) << std::endl; + std::cout << " BadPackage: " << std::format("0x{:08X}", std::uint32_t(p.mType)) << std::endl; } if (!p.mCellName.empty()) @@ -143,7 +143,7 @@ namespace std::ostringstream stream; std::visit([&](auto value) { stream << value; }, ss.mValue); - std::string result = Misc::StringUtils::format("%-12s %-32s %2s %s", typeStr, funcStr, operStr, stream.str()); + std::string result = std::format("{:<12} {:<32} {:2} {}", typeStr, funcStr, operStr, stream.str()); return result; } @@ -175,12 +175,12 @@ namespace { for (const ESM::Transport::Dest& dest : transport) { - std::cout << " Destination Position: " << Misc::StringUtils::format("%12.3f", dest.mPos.pos[0]) << "," - << Misc::StringUtils::format("%12.3f", dest.mPos.pos[1]) << "," - << Misc::StringUtils::format("%12.3f", dest.mPos.pos[2]) << ")" << std::endl; - std::cout << " Destination Rotation: " << Misc::StringUtils::format("%9.6f", dest.mPos.rot[0]) << "," - << Misc::StringUtils::format("%9.6f", dest.mPos.rot[1]) << "," - << Misc::StringUtils::format("%9.6f", dest.mPos.rot[2]) << ")" << std::endl; + std::cout << " Destination Position: " << std::format("{:12.3f}", dest.mPos.pos[0]) << "," + << std::format("{:12.3f}", dest.mPos.pos[1]) << "," << std::format("{:12.3f}", dest.mPos.pos[2]) + << ")" << std::endl; + std::cout << " Destination Rotation: " << std::format("{:9.6f}", dest.mPos.rot[0]) << "," + << std::format("{:9.6f}", dest.mPos.rot[1]) << "," << std::format("{:9.6f}", dest.mPos.rot[2]) + << ")" << std::endl; if (!dest.mCellName.empty()) std::cout << " Destination Cell: " << dest.mCellName << std::endl; } @@ -582,7 +582,7 @@ namespace EsmTool std::cout << " Water Level: " << mData.mWater << std::endl; } else - std::cout << " Map Color: " << Misc::StringUtils::format("0x%08X", mData.mMapColor) << std::endl; + std::cout << " Map Color: " << std::format("0x{:08X}", mData.mMapColor) << std::endl; std::cout << " RefId counter: " << mData.mRefNumCounter << std::endl; std::cout << " Deleted: " << mIsDeleted << std::endl; } @@ -593,7 +593,7 @@ namespace EsmTool std::cout << " Name: " << mData.mName << std::endl; std::cout << " Description: " << mData.mDescription << std::endl; std::cout << " Playable: " << mData.mData.mIsPlayable << std::endl; - std::cout << " AI Services: " << Misc::StringUtils::format("0x%08X", mData.mData.mServices) << std::endl; + std::cout << " AI Services: " << std::format("0x{:08X}", mData.mData.mServices) << std::endl; for (size_t i = 0; i < mData.mData.mAttribute.size(); ++i) std::cout << " Attribute" << (i + 1) << ": " << attributeLabel(mData.mData.mAttribute[i]) << " (" << mData.mData.mAttribute[i] << ")" << std::endl; @@ -641,8 +641,8 @@ namespace EsmTool std::cout << " Flags: " << containerFlags(mData.mFlags) << std::endl; std::cout << " Weight: " << mData.mWeight << std::endl; for (const ESM::ContItem& item : mData.mInventory.mList) - std::cout << " Inventory: Count: " << Misc::StringUtils::format("%4d", item.mCount) - << " Item: " << item.mItem << std::endl; + std::cout << " Inventory: Count: " << std::format("{:4d}", item.mCount) << " Item: " << item.mItem + << std::endl; std::cout << " Deleted: " << mIsDeleted << std::endl; } @@ -679,8 +679,8 @@ namespace EsmTool std::cout << " Gold: " << mData.mData.mGold << std::endl; for (const ESM::ContItem& item : mData.mInventory.mList) - std::cout << " Inventory: Count: " << Misc::StringUtils::format("%4d", item.mCount) - << " Item: " << item.mItem << std::endl; + std::cout << " Inventory: Count: " << std::format("{:4d}", item.mCount) << " Item: " << item.mItem + << std::endl; for (const auto& spell : mData.mSpells.mList) std::cout << " Spell: " << spell << std::endl; @@ -692,7 +692,7 @@ namespace EsmTool std::cout << " AI Fight:" << (int)mData.mAiData.mFight << std::endl; std::cout << " AI Flee:" << (int)mData.mAiData.mFlee << std::endl; std::cout << " AI Alarm:" << (int)mData.mAiData.mAlarm << std::endl; - std::cout << " AI Services:" << Misc::StringUtils::format("0x%08X", mData.mAiData.mServices) << std::endl; + std::cout << " AI Services:" << std::format("0x{:08X}", mData.mAiData.mServices) << std::endl; for (const ESM::AIPackage& package : mData.mAiPackage.mList) printAIPackage(package); @@ -1067,8 +1067,8 @@ namespace EsmTool } for (const ESM::ContItem& item : mData.mInventory.mList) - std::cout << " Inventory: Count: " << Misc::StringUtils::format("%4d", item.mCount) - << " Item: " << item.mItem << std::endl; + std::cout << " Inventory: Count: " << std::format("{:4d}", item.mCount) << " Item: " << item.mItem + << std::endl; for (const auto& spell : mData.mSpells.mList) std::cout << " Spell: " << spell << std::endl; @@ -1080,7 +1080,7 @@ namespace EsmTool std::cout << " AI Fight:" << (int)mData.mAiData.mFight << std::endl; std::cout << " AI Flee:" << (int)mData.mAiData.mFlee << std::endl; std::cout << " AI Alarm:" << (int)mData.mAiData.mAlarm << std::endl; - std::cout << " AI Services:" << Misc::StringUtils::format("0x%08X", mData.mAiData.mServices) << std::endl; + std::cout << " AI Services:" << std::format("0x{:08X}", mData.mAiData.mServices) << std::endl; for (const ESM::AIPackage& package : mData.mAiPackage.mList) printAIPackage(package); @@ -1191,8 +1191,8 @@ namespace EsmTool std::cout << " Variable: " << variable << std::endl; std::cout << " ByteCode: "; - for (const unsigned char& byte : mData.mScriptData) - std::cout << Misc::StringUtils::format("%02X", (int)(byte)); + for (unsigned char byte : mData.mScriptData) + std::cout << std::format("{:02X}", byte); std::cout << std::endl; if (mPrintPlain)