From cd9706da2a5329065784c93bedfa7969526feb78 Mon Sep 17 00:00:00 2001 From: Foereaper Date: Tue, 19 Nov 2024 20:29:11 +0100 Subject: [PATCH] Replace stringstream subdirectory map id parsing --- ElunaLoader.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/ElunaLoader.cpp b/ElunaLoader.cpp index c1369caa50..6f005ba496 100644 --- a/ElunaLoader.cpp +++ b/ElunaLoader.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #if defined USING_BOOST #include @@ -215,25 +216,18 @@ void ElunaLoader::ReadFiles(lua_State* L, std::string path) if (fs::is_regular_file(dir_iter->status())) { - int32 mapId; + // default to all maps + int32 mapId = -1; // strip base folder path and trailing slash from fullpath std::string subfolder = dir_iter->path().generic_string(); subfolder = subfolder.erase(0, lua_folderpath.size() + 1); - // stringstream used for conversion - std::stringstream ss; + // convert subfolder name to an integer + auto [ptr, ec] = std::from_chars(subfolder.data(), subfolder.data() + subfolder.size(), mapId); - // push subfolder int to subMapId - ss << subfolder; - ss >> mapId; - - // if this failed, then we load the script for all maps - if (ss.fail()) - mapId = -1; - - // just in case we have a subfolder named an int less than all.. - if (mapId < -1) + // default to all maps on invalid map id or map id less than -1 + if (ec == std::errc::invalid_argument || ec == std::errc::result_out_of_range || mapId < -1) mapId = -1; // was file, try add