diff --git a/source/code/HelpModInfoState.cpp b/source/code/HelpModInfoState.cpp index e4cf0a8..4008e01 100644 --- a/source/code/HelpModInfoState.cpp +++ b/source/code/HelpModInfoState.cpp @@ -27,7 +27,6 @@ https://blockattack.net #include "common.h" #include "sago/SagoMisc.hpp" #include "os.hpp" -#include #include struct Mod { @@ -71,7 +70,7 @@ static void initMods(std::vector& mod_list) { static void appendMods(const std::vector& mod_files, const std::string& dir, std::vector& mods_available) { for (const std::string& mod : mod_files) { - if (!boost::ends_with(mod, ".data")) { + if (!mod.ends_with(".data")) { continue; } Mod m; diff --git a/source/code/ModInfo.cpp b/source/code/ModInfo.cpp index 92686e9..d3737c1 100644 --- a/source/code/ModInfo.cpp +++ b/source/code/ModInfo.cpp @@ -26,7 +26,7 @@ http://blockattack.net #include "rapidjson/document.h" #include #include -#include +#include "common.h" void ModInfo::InitModList(const std::vector& modlist) { this->mod_list = modlist; @@ -44,8 +44,7 @@ void ModInfo::InitModList(const std::vector& modlist) { const auto& t = document.GetObject().FindMember("sprites"); if (t != document.MemberEnd() && t->value.IsString()) { std::string sprites = t->value.GetString(); - std::vector sprites_vector; - boost::split(sprites_vector, sprites, boost::is_any_of(",")); + std::vector sprites_vector = split_string(sprites, ","); sprite_filename_list.insert(sprite_filename_list.end(), sprites_vector.begin(), sprites_vector.end()); } } @@ -56,8 +55,7 @@ void ModInfo::ParseModFile(const std::string& content) { std::istringstream ss(content); std::string line; while (std::getline(ss, line)) { - std::vector line_vector; - boost::split(line_vector, line, boost::is_any_of(",")); + std::vector line_vector = split_string(line, ","); if (line_vector.size() < 2) { std::cerr << "skipping " << line << "\n"; continue; diff --git a/source/code/common.cpp b/source/code/common.cpp index 2b59fcc..8dedc20 100644 --- a/source/code/common.cpp +++ b/source/code/common.cpp @@ -59,6 +59,24 @@ int str2int(const std::string& str2parse) { } } +std::vector split_string(const std::string& input, const std::string& sep) +{ + std::vector out; + if (sep.empty()) + { + out.push_back(input); + return out; + } + std::size_t start = 0; + std::size_t pos = 0; + while ((pos = input.find(sep, start)) != std::string::npos) { + out.emplace_back(input, start, pos - start); + start = pos + sep.size(); + } + out.emplace_back(input, start); + return out; +} + /** * Takes a number of milliseconds and returns the value in commonTime format. */ diff --git a/source/code/common.h b/source/code/common.h index 8915991..e02d30e 100644 --- a/source/code/common.h +++ b/source/code/common.h @@ -33,6 +33,7 @@ https://blockattack.net #include #include #include +#include #include #include #include @@ -66,6 +67,14 @@ void dieOnNullptr(bool, const char* msg); */ double str2double(const std::string &str2parse) __attribute__((const)); +/** + * Split a string into multiple strings using the given separator + * @param input The string to split + * @param sep The separator + * @return A vector of strings + */ +std::vector split_string(const std::string& input, const std::string& sep); + class TimeHandler { public: diff --git a/source/code/main.cpp b/source/code/main.cpp index 51615ca..ec2183a 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -61,7 +61,6 @@ https://blockattack.net #include "common.h" #include "gamecontroller.h" -#include #include #include #include "levelselect.hpp" @@ -1085,10 +1084,6 @@ int main(int argc, char* argv[]) { OsCreateSaveFolder(); writeStateFile(argv[0], PHYSFS_getBaseDir()); PhysFsSetSearchPath(config.search_paths, config.savepath); - /*if (globalData.modList.empty() && sago::FileExists(MODLIST_TXT)) { - std::string modString = sago::GetFileContent(MODLIST_TXT); - boost::split(globalData.modList, modString, boost::is_any_of(",")); - }*/ globalData.modinfo.InitModList(globalData.modList); if (sago::FileExists(MODLIST_TXT)) { globalData.modinfo.ParseModFile(sago::GetFileContent(MODLIST_TXT)); diff --git a/source/code/themes.cpp b/source/code/themes.cpp index 0d23292..e8cce00 100644 --- a/source/code/themes.cpp +++ b/source/code/themes.cpp @@ -31,7 +31,6 @@ https://www.blockattack.net #include "nlohmann/json.hpp" #include #include "global.hpp" -#include #include using json = nlohmann::json; @@ -329,7 +328,7 @@ void ThemesInit() { ThemesFillMissingFields(themes[0]); const std::vector& theme_files = sago::GetFileList("themes"); for (const std::string& filename : theme_files) { - if (boost::algorithm::ends_with(filename,".json")) { + if (filename.ends_with(".json")) { ThemesReadDataFromFile("themes/"+filename); } } @@ -442,7 +441,7 @@ void ThemesInitCustomBackgrounds() { bool first = true; for (const std::string& filename : custom_backgrounds) { std::cout << "Found custom background " << filename << "\n"; - if (boost::algorithm::ends_with(filename, ".png") || boost::algorithm::ends_with(filename, ".jpg")) { + if (filename.ends_with(".png") || filename.ends_with(".jpg")) { BackGroundData bg; bg.name = filename; std::string texture_name = fmt::format("custom_background_{}",filename);; @@ -501,7 +500,7 @@ void ThemesSaveBackgroundData(const std::string& name, const BackGroundData& dat void ThemesLoadCustomBorders() { const std::vector& border_files = sago::GetFileList("borders"); for (const std::string& filename : border_files) { - if (boost::algorithm::ends_with(filename, ".json")) { + if (filename.ends_with(".json")) { std::string filepath = fmt::format("borders/{}", filename); std::string s = sago::GetFileContent(filepath); if (s.empty()) { @@ -525,7 +524,7 @@ void ThemesLoadCustomBorders() { void ThemesLoadCustomBackgrounds() { const std::vector& background_files = sago::GetFileList("backgrounds"); for (const std::string& filename : background_files) { - if (boost::algorithm::ends_with(filename, ".json")) { + if (filename.ends_with(".json")) { std::string filepath = fmt::format("backgrounds/{}", filename); std::string s = sago::GetFileContent(filepath); if (s.empty()) {