Skip to content

Commit

Permalink
Replace stringstream subdirectory map id parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Foereaper committed Nov 19, 2024
1 parent d46d607 commit cd9706d
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions ElunaLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <fstream>
#include <sstream>
#include <thread>
#include <charconv>

#if defined USING_BOOST
#include <boost/filesystem.hpp>
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cd9706d

Please sign in to comment.