Skip to content

Commit cd9706d

Browse files
committed
Replace stringstream subdirectory map id parsing
1 parent d46d607 commit cd9706d

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

ElunaLoader.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <fstream>
1313
#include <sstream>
1414
#include <thread>
15+
#include <charconv>
1516

1617
#if defined USING_BOOST
1718
#include <boost/filesystem.hpp>
@@ -215,25 +216,18 @@ void ElunaLoader::ReadFiles(lua_State* L, std::string path)
215216

216217
if (fs::is_regular_file(dir_iter->status()))
217218
{
218-
int32 mapId;
219+
// default to all maps
220+
int32 mapId = -1;
219221

220222
// strip base folder path and trailing slash from fullpath
221223
std::string subfolder = dir_iter->path().generic_string();
222224
subfolder = subfolder.erase(0, lua_folderpath.size() + 1);
223225

224-
// stringstream used for conversion
225-
std::stringstream ss;
226+
// convert subfolder name to an integer
227+
auto [ptr, ec] = std::from_chars(subfolder.data(), subfolder.data() + subfolder.size(), mapId);
226228

227-
// push subfolder int to subMapId
228-
ss << subfolder;
229-
ss >> mapId;
230-
231-
// if this failed, then we load the script for all maps
232-
if (ss.fail())
233-
mapId = -1;
234-
235-
// just in case we have a subfolder named an int less than all..
236-
if (mapId < -1)
229+
// default to all maps on invalid map id or map id less than -1
230+
if (ec == std::errc::invalid_argument || ec == std::errc::result_out_of_range || mapId < -1)
237231
mapId = -1;
238232

239233
// was file, try add

0 commit comments

Comments
 (0)