Skip to content

Commit

Permalink
replace the last std::regex usage where the regex is known at compile…
Browse files Browse the repository at this point in the history
… time
  • Loading branch information
DubbleClick committed Mar 8, 2025
1 parent a545e96 commit 8a8e895
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 45 deletions.
3 changes: 0 additions & 3 deletions GWToolboxdll/Modules/InventoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1958,9 +1958,6 @@ void InventoryManager::Draw(IDirect3DDevice9*)
// Are you sure prompt; at this point we've already got the list of items via FetchPotentialItems()
ImGui::Text("You're about to salvage %d item%s:", potential_salvage_all_items.size(), potential_salvage_all_items.size() == 1 ? "" : "s");
ImGui::TextDisabled("Untick an item to skip salvaging");
static const std::regex sanitiser("<[^>]+>");
static const std::wregex wsanitiser(L"<[^>]+>");
static const std::wstring wiki_url(L"https://wiki.guildwars.com/wiki/");
const float& font_scale = ImGui::GetIO().FontGlobalScale;
const float wiki_btn_width = 50.0f * font_scale;
static float longest_item_name_length = 280.0f * font_scale;
Expand Down
41 changes: 19 additions & 22 deletions GWToolboxdll/Windows/CompletionWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,33 +334,32 @@ namespace {
if (!(dialog_body && wcsncmp(dialog_body, L"\x8102\x2B9D\xDE1D\xB19F\x52DD", 5) == 0)) {
return; // Not devotion dialog "Miniatures on display"
}
const std::wregex displayed_miniatures(L"\x2\x102\x2([^\x102\x2]+)");
std::wsmatch m;
std::wstring subject(dialog_body);
static constexpr ctll::fixed_string displayed_miniatures = L"\x2\x102\x2([^\x102\x2]+)";
std::wstring_view subject(dialog_body);
std::wstring msg;
const auto cc = character_completion[GetPlayerName()];
auto& minipets_unlocked = cc->minipets_unlocked;
minipets_unlocked.clear();
while (std::regex_search(subject, m, displayed_miniatures)) {
std::wstring miniature_encoded_name(m[1].str());
for (auto m : ctre::search_all<displayed_miniatures>(subject)) {
std::wstring miniature_encoded_name = m.get<1>().to_string();
for (size_t i = 0; i < _countof(encoded_minipet_names); i++) {
if (encoded_minipet_names[i] == miniature_encoded_name) {
ArrayBoolSet(minipets_unlocked, i, true);
break;
}
}
subject = m.suffix().str();
subject.remove_prefix(std::distance(subject.begin(), m.get<0>().end()));
}
const std::wregex available_miniatures(L"\x2\x109\x2([^\x109\x2]+)");
while (std::regex_search(subject, m, available_miniatures)) {
std::wstring miniature_encoded_name(m[1].str());
static constexpr ctll::fixed_string available_miniatures = L"\x2\x109\x2([^\x109\x2]+)";
for (auto m : ctre::search_all<available_miniatures>(subject)) {
std::wstring miniature_encoded_name = m.get<1>().to_string();
for (size_t i = 0; i < _countof(encoded_minipet_names); i++) {
if (encoded_minipet_names[i] == miniature_encoded_name) {
ArrayBoolSet(minipets_unlocked, i, true);
break;
}
}
subject = m.suffix().str();
subject.remove_prefix(std::distance(subject.begin(), m.get<0>().end()));
}
Instance().CheckProgress();
}
Expand Down Expand Up @@ -402,21 +401,19 @@ namespace {
if (this_dialog_button == available_dialogs.end()) {
return;
}
const std::wregex miniature_displayed_regex(L"\x8102\x2B91\xDAA2\xD19F\x32DB\x10A([^\x1]+)");
std::wsmatch m;
const std::wstring subject((*this_dialog_button)->message);
const std::wstring_view subject((*this_dialog_button)->message);
std::wstring msg;
const auto cc = character_completion[GetPlayerName()];
auto& minipets_unlocked = cc->minipets_unlocked;
if (!std::regex_search(subject, m, miniature_displayed_regex)) {
return;
}
const std::wstring miniature_encoded_name(m[1].str());
for (size_t i = 0; i < _countof(encoded_minipet_names); i++) {
if (encoded_minipet_names[i] == miniature_encoded_name) {
ArrayBoolSet(minipets_unlocked, i, true);
Instance().CheckProgress();
break;
static constexpr ctll::fixed_string miniature_displayed_regex = L"\x8102\x2B91\xDAA2\xD19F\x32DB\x10A([^\x1]+)";
if (auto m = ctre::search<miniature_displayed_regex>(subject)) {
const std::wstring miniature_encoded_name = m.get<1>().to_string();
for (size_t i = 0; i < _countof(encoded_minipet_names); i++) {
if (encoded_minipet_names[i] == miniature_encoded_name) {
ArrayBoolSet(minipets_unlocked, i, true);
Instance().CheckProgress();
break;
}
}
}
}
Expand Down
36 changes: 16 additions & 20 deletions GWToolboxdll/Windows/TravelWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <GWCA/Managers/QuestMgr.h>

namespace {

GW::HookEntry ChatCmd_HookEntry;
bool search_in_english = true;

Expand Down Expand Up @@ -393,22 +392,19 @@ namespace {
std::string compare = TextUtils::ToLower(TextUtils::RemovePunctuation(TextUtils::WStringToString(s)));
const std::string first_word = compare.substr(0, compare.find(' '));

static const std::regex district_regex("([a-z]{2,3})(\\d+)?");
std::smatch m;
if (!std::regex_search(first_word, m, district_regex)) {
return false;
}
// Shortcut words e.g "/tp ae" for american english
const auto& shorthand_outpost = shorthand_district_names.find(m[1].str());
if (shorthand_outpost == shorthand_district_names.end()) {
return false;
}
district = shorthand_outpost->second.district;
if (m.size() > 2 && !TextUtils::ParseUInt(m[2].str().c_str(), &number)) {
number = 0;
static constexpr ctll::fixed_string district_regex = "([a-z]{2,3})(\\d+)?";
if (auto m = ctre::match<district_regex>(first_word)) {
const auto& shorthand_outpost = shorthand_district_names.find(m.get<1>().to_string());
if (shorthand_outpost == shorthand_district_names.end()) {
return false;
}
district = shorthand_outpost->second.district;
if (m.size() > 2 && !TextUtils::ParseUInt(m.get<2>().to_string().c_str(), &number)) {
number = 0;
}
return true;
}

return true;
return false;
}

void CHAT_CMD_FUNC(CmdTP)
Expand Down Expand Up @@ -606,9 +602,9 @@ void TravelWindow::Initialize()
district = GW::Constants::District::Current;
district_number = 0;

GW::Chat::CreateCommand(&ChatCmd_HookEntry,L"tp", &CmdTP);
GW::Chat::CreateCommand(&ChatCmd_HookEntry,L"to", &CmdTP);
GW::Chat::CreateCommand(&ChatCmd_HookEntry,L"travel", &CmdTP);
GW::Chat::CreateCommand(&ChatCmd_HookEntry, L"tp", &CmdTP);
GW::Chat::CreateCommand(&ChatCmd_HookEntry, L"to", &CmdTP);
GW::Chat::CreateCommand(&ChatCmd_HookEntry, L"travel", &CmdTP);

for (const auto message_id : messages_to_hook) {
RegisterUIMessageCallback(&OnUIMessage_HookEntry, message_id, OnUIMessage);
Expand Down Expand Up @@ -828,7 +824,7 @@ GW::Constants::MapID TravelWindow::GetNearestOutpost(const GW::Constants::MapID
{GW::Constants::MapID::Dry_Top, GW::Constants::MapID::Aurora_Glade},
{GW::Constants::MapID::Iron_Horse_Mine, GW::Constants::MapID::Yaks_Bend_outpost},
{GW::Constants::MapID::Fahranur_The_First_City, GW::Constants::MapID::Blacktide_Den}, // 8 player outpost is better to start with
{GW::Constants::MapID::Cliffs_of_Dohjok, GW::Constants::MapID::Blacktide_Den}, // 8 player outpost is better to start with
{GW::Constants::MapID::Cliffs_of_Dohjok, GW::Constants::MapID::Blacktide_Den}, // 8 player outpost is better to start with
};

if (special_cases.contains(map_to)) {
Expand Down

0 comments on commit 8a8e895

Please sign in to comment.