From 11fa1c51191bcc91cb8433559ce2309b937f760c Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 13 Nov 2022 23:44:30 +0100 Subject: [PATCH] Add case insensitive search for developer console input field This has been requested by a user. This change will allow for searching convars from partial input regardless of the case. --- r5dev/gameui/IConsole.cpp | 2 +- r5dev/public/utility/utility.cpp | 13 +++++++++++++ r5dev/public/utility/utility.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/r5dev/gameui/IConsole.cpp b/r5dev/gameui/IConsole.cpp index 535c80d2..13a9beca 100644 --- a/r5dev/gameui/IConsole.cpp +++ b/r5dev/gameui/IConsole.cpp @@ -495,7 +495,7 @@ void CConsole::FindFromPartial(void) { return; } - if (suggest.m_svName.find(m_szInputBuf) == string::npos) + if (!HasPartial(suggest.m_svName, m_szInputBuf)) { continue; } diff --git a/r5dev/public/utility/utility.cpp b/r5dev/public/utility/utility.cpp index 7cbfbffc..9fd03394 100644 --- a/r5dev/public/utility/utility.cpp +++ b/r5dev/public/utility/utility.cpp @@ -245,6 +245,19 @@ char* StripQuotes(const char* pInBuffer, char* pOutBuffer, int nOutBufferSize) return out; } +/////////////////////////////////////////////////////////////////////////////// +// For finding a partial string within input (case insensitive). +bool HasPartial(const string& svInput, const string& svPartial) +{ + auto it = std::search( svInput.begin(), svInput.end(), + svPartial.begin(), svPartial.end(), [](char ci, char cp) + { + return std::toupper(ci) == std::toupper(cp); + } + ); + return (it != svInput.end()); +} + /////////////////////////////////////////////////////////////////////////////// // For checking if file name has a specific extension. bool HasExtension(const string& svInput, const string& svExtension) diff --git a/r5dev/public/utility/utility.h b/r5dev/public/utility/utility.h index 0caedc93..860c95b3 100644 --- a/r5dev/public/utility/utility.h +++ b/r5dev/public/utility/utility.h @@ -20,6 +20,7 @@ char* StripQuotes(const char* pInBuffer, char* pOutBuffer, int nOutBufferSize); ///////////////////////////////////////////////////////////////////////////// // String +bool HasPartial(const string& svInput, const string& svPartial); bool HasExtension(const string& svInput, const string& svExtension); string GetExtension(const string& svInput, bool bReturnOriginal = false, bool bKeepDelimiter = false); string RemoveExtension(const string& svInput);