Skip to content

Commit

Permalink
more std::regex -> ctre
Browse files Browse the repository at this point in the history
  • Loading branch information
DubbleClick committed Mar 8, 2025
1 parent f45b0c4 commit 3150170
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
12 changes: 6 additions & 6 deletions GWToolboxdll/Modules/GameSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1483,15 +1483,15 @@ void PendingChatMessage::Init()
}
}

std::vector<std::wstring> PendingChatMessage::SanitiseForSend()
std::vector<std::wstring> PendingChatMessage::SanitiseForSend() const
{
const std::wregex no_tags(L"<[^>]+>");
const std::wregex no_new_lines(L"\n");
std::wstring sanitised, sanitised2, temp;
std::regex_replace(std::back_inserter(sanitised), output_message.begin(), output_message.end(), no_tags, L"");
std::regex_replace(std::back_inserter(sanitised2), sanitised.begin(), sanitised.end(), no_new_lines, L"|");
const std::wstring sanitised = TextUtils::ctre_regex_replace<L"<[^>]+>">(output_message, L"");
const std::wstring sanitised2 = TextUtils::ctre_regex_replace<L"\n">(sanitised, L"|");

// Split the string by '|' character
std::vector<std::wstring> parts;
std::wstringstream wss(sanitised2);
std::wstring temp;
while (std::getline(wss, temp, L'|')) {
parts.push_back(temp);
}
Expand Down
4 changes: 2 additions & 2 deletions GWToolboxdll/Modules/Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1307,8 +1307,8 @@ IDirect3DTexture9** Resources::GetItemImage(const std::wstring& item_name)
}
const std::string item_name_str = TextUtils::WStringToString(item_name);
// matches any characters that need to be escaped in RegEx
static const std::regex specialChars{R"([-[\]{}()*+?.,\^$|#\s])"};
const std::string sanitized = std::regex_replace(item_name_str, specialChars, R"(\$&)");
static const std::regex SPECIAL_CHARS{R"([-[\]{}()*+?.,\^$|#\s])"};
const std::string sanitized = std::regex_replace(item_name_str, SPECIAL_CHARS, R"(\$&)");
std::smatch m;
// Find first png image that has an alt tag matching the html encoded title of the page
char regex_str[255];
Expand Down
4 changes: 1 addition & 3 deletions GWToolboxdll/Utils/GuiUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,7 @@ namespace GuiUtils {
{
if (!sanitised && !decoded_ws.empty()) {
sanitised = true;
static const std::wregex sanitiser(L"<[^>]+>");
auto sanitised_ws = std::regex_replace(decoded_ws, sanitiser, L"");
decoded_ws = std::move(sanitised_ws);
decoded_ws = TextUtils::ctre_regex_replace<L"<[^>]+>">(decoded_ws, L"");
}
}

Expand Down

0 comments on commit 3150170

Please sign in to comment.