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.
This commit is contained in:
Kawe Mazidjatari 2022-11-13 23:44:30 +01:00
parent cf1adef1a2
commit 11fa1c5119
3 changed files with 15 additions and 1 deletions

View File

@ -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;
}

View File

@ -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)

View File

@ -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);