diff --git a/Source/Network/TextEncoding.cpp b/Source/Network/TextEncoding.cpp index 6afb259f5..61aaa6824 100644 --- a/Source/Network/TextEncoding.cpp +++ b/Source/Network/TextEncoding.cpp @@ -160,7 +160,7 @@ std::wstring LowercaseWide(const std::string& text) { // OFFSET: 0x0058D6B0 // FUNCTION: fn_02795 -int FindSubstring(const char* text, int codePage, const char* pattern) { - return static_cast(LowercaseWide(text).find(LowercaseWide(pattern))); +int FindSubstring(std::string_view text, std::string_view pattern) { + return static_cast(LowercaseWide(text.data()).find(LowercaseWide(pattern.data()))); } diff --git a/Source/Network/TextEncoding.h b/Source/Network/TextEncoding.h index 2acde88e6..8c58720fc 100644 --- a/Source/Network/TextEncoding.h +++ b/Source/Network/TextEncoding.h @@ -2,6 +2,7 @@ #define RAGNAROK_SOURCE_NETWORK_TEXTENCODING_H #include +#include #include extern UINT g_textCodePage; @@ -14,7 +15,7 @@ std::string ToUtf8(const std::string& text, UINT codePage); void LowercaseText(std::string& text); std::wstring LowercaseWide(const std::string& text); -int FindSubstring(const char* text, int codePage, const char* pattern); +int FindSubstring(std::string_view text, std::string_view pattern); std::wstring DecodeText(UINT codePage, const std::string& text); std::string EncodeText(UINT codePage, const std::wstring& text); diff --git a/Source/UI/ProbabilityTable/UIProbabilityTable.cpp b/Source/UI/ProbabilityTable/UIProbabilityTable.cpp index e701cdd4b..ed79faceb 100644 --- a/Source/UI/ProbabilityTable/UIProbabilityTable.cpp +++ b/Source/UI/ProbabilityTable/UIProbabilityTable.cpp @@ -492,7 +492,7 @@ void CUIProbabilityTable::Search() { list = this->m_list; auto matches = [keyword](const ProbabilityTable::CItemData& data) { - return FindSubstring(data.name.c_str(), static_cast(data.name.size()), keyword.data()) != -1; + return FindSubstring(data.name, keyword) != -1; }; auto start = list->data.begin(); diff --git a/Source/UI/ProbabilityTable/UIProbabilityTableEvents.cpp b/Source/UI/ProbabilityTable/UIProbabilityTableEvents.cpp index b63cdc2c4..eb3c2c30b 100644 --- a/Source/UI/ProbabilityTable/UIProbabilityTableEvents.cpp +++ b/Source/UI/ProbabilityTable/UIProbabilityTableEvents.cpp @@ -99,7 +99,7 @@ void CUIProbabilityTable::SetItem(int itemId) { // FUNCTION: fn_16210 int HighlightKeyword(std::string& text, std::string_view keyword, std::string_view prefix, std::string_view suffix) { int count = 0; - if (FindSubstring(text.c_str(), static_cast(text.size()), keyword.data()) == -1) { + if (FindSubstring(text, keyword) == -1) { return 0; } diff --git a/Source/UI/Quest/UIRenewQuestUI.cpp b/Source/UI/Quest/UIRenewQuestUI.cpp index 465ed9de6..daa040562 100644 --- a/Source/UI/Quest/UIRenewQuestUI.cpp +++ b/Source/UI/Quest/UIRenewQuestUI.cpp @@ -961,14 +961,7 @@ bool CUIRenewQuestUI::MatchesFilter(const RenewQuestInfo& info) const { return false; } - if (!this->searchText.empty()) { - if (FindSubstring(info.summary.c_str(), static_cast(info.summary.size()), this->searchText.c_str()) == -1 && - FindSubstring(info.m_title.c_str(), static_cast(info.m_title.size()), this->searchText.c_str()) == -1) { - return false; - } - } - - return true; + return this->searchText.empty() || FindSubstring(info.summary, this->searchText) != -1 || FindSubstring(info.m_title, this->searchText) != -1; } // OFFSET: 0x00A660E0