From fcee0f2bfd36e038ad7c55e0fa2f1a87bcdf377f Mon Sep 17 00:00:00 2001 From: Malkierian Date: Sat, 7 Jun 2025 08:16:01 -0700 Subject: [PATCH] Remove backslash escaping from Sanitize. Remove duplicate Sanitize from Context and make it use SohUtils. Fix typo. --- soh/soh/Enhancements/randomizer/context.cpp | 22 ++----------------- .../Enhancements/randomizer/randomizer.cpp | 2 +- soh/soh/util.cpp | 15 ------------- 3 files changed, 3 insertions(+), 36 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/context.cpp b/soh/soh/Enhancements/randomizer/context.cpp index 89fb1dc85..a0f7f223b 100644 --- a/soh/soh/Enhancements/randomizer/context.cpp +++ b/soh/soh/Enhancements/randomizer/context.cpp @@ -11,8 +11,7 @@ #include "fishsanity.h" #include "macros.h" #include "3drando/hints.hpp" -#include "soh/SohGui/SohGui.hpp" - +#include "soh/util.h" #include "../kaleido.h" #include @@ -372,25 +371,8 @@ GetItemEntry Context::GetFinalGIEntry(const RandomizerCheck rc, const bool check return giEntry; } -std::string sanitize(std::string stringValue) { - // Add backslashes. - for (auto i = stringValue.begin();;) { - auto const pos = - std::find_if(i, stringValue.end(), [](char const c) { return '\\' == c || '\'' == c || '"' == c; }); - if (pos == stringValue.end()) { - break; - } - i = std::next(stringValue.insert(pos, '\\'), 2); - } - - // Removes others. - std::erase_if(stringValue, [](char const c) { return '\n' == c || '\r' == c || '\0' == c || '\x1A' == c; }); - - return stringValue; -} - void Context::ParseSpoiler(const char* spoilerFileName) { - std::ifstream spoilerFileStream(sanitize(spoilerFileName)); + std::ifstream spoilerFileStream(SohUtils::Sanitize(spoilerFileName)); if (!spoilerFileStream) { return; } diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index cc9c2b044..7809a39c1 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -372,7 +372,7 @@ bool Randomizer::SpoilerFileExists(const char* spoilerFileName) { SohGui::RegisterPopup( "Old Spoiler Version", "The spoiler file located at\n" + std::string(spoilerFileName) + - "\nwas made by an version that doesn't match the currently running version.\n" + + "\nwas made by a version that doesn't match the currently running version.\n" + "Loading for this file has been cancelled."); } } diff --git a/soh/soh/util.cpp b/soh/soh/util.cpp index 19ee68201..a991c35ca 100644 --- a/soh/soh/util.cpp +++ b/soh/soh/util.cpp @@ -369,21 +369,6 @@ void SohUtils::CopyStringToCharArray(char* destination, std::string source, size } std::string SohUtils::Sanitize(std::string stringValue) { - // Add backslashes. - for (auto i = stringValue.begin();;) { - auto const pos = - std::find_if(i, stringValue.end(), [](char const c) { return '\\' == c || '\'' == c || '"' == c; }); - if (pos == stringValue.end()) { - break; - } - auto checkPos = pos + 1; - auto reversePos = pos - 1; - if (*checkPos != '\\' && *reversePos != '\\') { - i = std::next(stringValue.insert(pos, '\\'), 2); - } - } - - // Removes others. stringValue.erase(std::remove_if(stringValue.begin(), stringValue.end(), [](char const c) { return '\n' == c || '\r' == c || '\0' == c || '\x1A' == c; }), stringValue.end());