mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-08-22 14:23:44 -07:00
Remove backslash escaping from Sanitize.
Remove duplicate Sanitize from Context and make it use SohUtils. Fix typo.
This commit is contained in:
parent
336400e4b1
commit
fcee0f2bfd
3 changed files with 3 additions and 36 deletions
|
@ -11,8 +11,7 @@
|
||||||
#include "fishsanity.h"
|
#include "fishsanity.h"
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
#include "3drando/hints.hpp"
|
#include "3drando/hints.hpp"
|
||||||
#include "soh/SohGui/SohGui.hpp"
|
#include "soh/util.h"
|
||||||
|
|
||||||
#include "../kaleido.h"
|
#include "../kaleido.h"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -372,25 +371,8 @@ GetItemEntry Context::GetFinalGIEntry(const RandomizerCheck rc, const bool check
|
||||||
return giEntry;
|
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) {
|
void Context::ParseSpoiler(const char* spoilerFileName) {
|
||||||
std::ifstream spoilerFileStream(sanitize(spoilerFileName));
|
std::ifstream spoilerFileStream(SohUtils::Sanitize(spoilerFileName));
|
||||||
if (!spoilerFileStream) {
|
if (!spoilerFileStream) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -372,7 +372,7 @@ bool Randomizer::SpoilerFileExists(const char* spoilerFileName) {
|
||||||
SohGui::RegisterPopup(
|
SohGui::RegisterPopup(
|
||||||
"Old Spoiler Version",
|
"Old Spoiler Version",
|
||||||
"The spoiler file located at\n" + std::string(spoilerFileName) +
|
"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.");
|
"Loading for this file has been cancelled.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -369,21 +369,6 @@ void SohUtils::CopyStringToCharArray(char* destination, std::string source, size
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SohUtils::Sanitize(std::string stringValue) {
|
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(),
|
stringValue.erase(std::remove_if(stringValue.begin(), stringValue.end(),
|
||||||
[](char const c) { return '\n' == c || '\r' == c || '\0' == c || '\x1A' == c; }),
|
[](char const c) { return '\n' == c || '\r' == c || '\0' == c || '\x1A' == c; }),
|
||||||
stringValue.end());
|
stringValue.end());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue