StringUtil: Fix inequal-length EqualNoCase
This commit is contained in:
parent
8170475c6b
commit
a957fb669d
|
@ -63,10 +63,10 @@ static inline int Strncasecmp(const char* s1, const char* s2, std::size_t n)
|
|||
// Case-insensitive equality of string views.
|
||||
static inline bool EqualNoCase(std::string_view s1, std::string_view s2)
|
||||
{
|
||||
if (s1.empty() || s2.empty())
|
||||
return (s1.empty() == s2.empty());
|
||||
if (s1.length() != s2.length())
|
||||
return false;
|
||||
|
||||
return (Strncasecmp(s1.data(), s2.data(), std::min(s1.length(), s2.length())) == 0);
|
||||
return (Strncasecmp(s1.data(), s2.data(), s1.length()) == 0);
|
||||
}
|
||||
|
||||
/// Wrapper around std::from_chars
|
||||
|
|
|
@ -1358,12 +1358,12 @@ static constexpr const std::array s_controller_display_names = {
|
|||
TRANSLATE_NOOP("ControllerType", "PlayStation Mouse"),
|
||||
TRANSLATE_NOOP("ControllerType", "NeGcon")};
|
||||
|
||||
std::optional<ControllerType> Settings::ParseControllerTypeName(const char* str)
|
||||
std::optional<ControllerType> Settings::ParseControllerTypeName(std::string_view str)
|
||||
{
|
||||
int index = 0;
|
||||
for (const char* name : s_controller_type_names)
|
||||
{
|
||||
if (StringUtil::Strcasecmp(name, str) == 0)
|
||||
if (StringUtil::EqualNoCase(str, name))
|
||||
return static_cast<ControllerType>(index);
|
||||
|
||||
index++;
|
||||
|
|
|
@ -409,7 +409,7 @@ struct Settings
|
|||
static const char* GetAudioBackendName(AudioBackend backend);
|
||||
static const char* GetAudioBackendDisplayName(AudioBackend backend);
|
||||
|
||||
static std::optional<ControllerType> ParseControllerTypeName(const char* str);
|
||||
static std::optional<ControllerType> ParseControllerTypeName(std::string_view str);
|
||||
static const char* GetControllerTypeName(ControllerType type);
|
||||
static const char* GetControllerTypeDisplayName(ControllerType type);
|
||||
|
||||
|
|
Loading…
Reference in New Issue