From 432ddaa602c84732f8c1bfccae33625cfd1d67bc Mon Sep 17 00:00:00 2001 From: zzyyyl Date: Fri, 30 Sep 2022 00:25:27 +0800 Subject: [PATCH] =?UTF-8?q?rft:=20=E4=BD=BF=E7=94=A8=20asst::utils=20?= =?UTF-8?q?=E7=9A=84=20string=20=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/ResourceUpdater/ResourceUpdater.vcxproj | 1 + tools/ResourceUpdater/main.cpp | 45 +++++-------------- 2 files changed, 13 insertions(+), 33 deletions(-) diff --git a/tools/ResourceUpdater/ResourceUpdater.vcxproj b/tools/ResourceUpdater/ResourceUpdater.vcxproj index 0784826e8b..130b25921a 100644 --- a/tools/ResourceUpdater/ResourceUpdater.vcxproj +++ b/tools/ResourceUpdater/ResourceUpdater.vcxproj @@ -46,6 +46,7 @@ stdcpp20 /utf-8 /MP %(AdditionalOptions) stdc17 + $(ProjectDir)..\..\src\MeoAssistant;%(AdditionalIncludeDirectories) Console diff --git a/tools/ResourceUpdater/main.cpp b/tools/ResourceUpdater/main.cpp index 2dde25a848..a75d9210e1 100644 --- a/tools/ResourceUpdater/main.cpp +++ b/tools/ResourceUpdater/main.cpp @@ -2,6 +2,8 @@ #include #include +#include "Utils/AsstUtils.hpp" + #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 5054) @@ -22,33 +24,6 @@ #pragma GCC diagnostic pop #endif #include -#include - -std::string ReplaceAll(std::string str, const std::string& from, const std::string& to) -{ - size_t start_pos = 0; - while ((start_pos = str.find(from, start_pos)) != std::string::npos) { - str.replace(start_pos, from.length(), to); - start_pos += to.length(); // Handles case where 'to' is a substring of 'from' - } - return str; -} - -std::vector Split(const std::string& str, const std::string& delim) -{ - std::vector tokens; - size_t prev = 0, pos = 0; - do { - pos = str.find(delim, prev); - if (pos == std::string::npos) pos = str.length(); - std::string token = str.substr(prev, pos - prev); - if (!token.empty()) { - tokens.push_back(token); - } - prev = pos + delim.length(); - } while (pos < str.length() && prev < str.length()); - return tokens; -} static inline void ltrim(std::string& s) { @@ -403,7 +378,7 @@ bool update_infrast_data(const std::filesystem::path& input_dir, const std::file // 这里面有些是手动修改的,要保留 json::value& root = old_json; std::unordered_set rooms; - for (auto& buff_obj : buffs | std::views::values) { + for (auto& buff_obj : buffs | asst::views::values) { std::string raw_room_type = static_cast(buff_obj["roomType"]); // 为了兼容老版本的字段 orz @@ -653,6 +628,8 @@ bool update_battle_chars_info(const std::filesystem::path& input_dir, const std: bool update_recruitment_data(const std::filesystem::path& input_dir, const std::filesystem::path& output, bool is_base) { + using namespace asst::utils; + using asst::ranges::find_if, asst::views::filter; const auto& recruitment_file = input_dir / "gacha_table.json"; const auto& operators_file = input_dir / "character_table.json"; @@ -667,17 +644,19 @@ bool update_recruitment_data(const std::filesystem::path& input_dir, const std:: std::vector chars_list; std::string recruitment_details = recruitment_opt->at("recruitDetail").as_string(); remove_xml(recruitment_details); - auto splited = Split(ReplaceAll(recruitment_details, "\\n", ""), "★"); + _string_replace_all(recruitment_details, "\\n", ""); + auto splited = string_split(recruitment_details, "★"); bool is_useless = true; - for (const auto& s : splited) { - if (s.find("Lancet-2") != std::string::npos) { + auto not_empty = [](std::string_view str) -> bool { return !str.empty(); }; + for (auto s : splited | filter(not_empty)) { + if (s.find("Lancet-2") != std::string_view::npos) { is_useless = false; } if (is_useless) { continue; } - for (const auto& n : Split(Split(s, "\n")[0], "/")) { - std::string name = n; + for (auto n : string_split((string_split(s, "\n") | filter(not_empty)).front(), "/") | filter(not_empty)) { + std::string name(n); trim(name); chars_list.emplace_back(name); }