From f8f6d34f6a24a51c5fbdddc4205bbe2c19eb4d68 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Fri, 27 Apr 2018 19:34:34 +0200 Subject: [PATCH] GUI: Make the tab completion case insensitive in the debug console It made little sense for the tab-completion to be case sensitive while command execution itself is case insensitive. --- common/str.cpp | 37 +++++++++++++++++++++++++++++++++++++ common/str.h | 4 ++++ gui/debugger.cpp | 2 +- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/common/str.cpp b/common/str.cpp index 2ef67175cdf..a2dd2079df8 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -302,6 +302,23 @@ bool String::hasPrefix(const char *x) const { return *x == 0; } +bool String::hasPrefixIgnoreCase(const String &x) const { + return hasPrefixIgnoreCase(x.c_str()); +} + +bool String::hasPrefixIgnoreCase(const char *x) const { + assert(x != nullptr); + // Compare x with the start of _str. + const char *y = c_str(); + while (*x && tolower(*x) == tolower(*y)) { + ++x; + ++y; + } + // It's a prefix, if and only if all letters in x are 'used up' before + // _str ends. + return *x == 0; +} + bool String::hasSuffix(const String &x) const { return hasSuffix(x.c_str()); } @@ -322,6 +339,26 @@ bool String::hasSuffix(const char *x) const { return *x == 0; } +bool String::hasSuffixIgnoreCase(const String &x) const { + return hasSuffixIgnoreCase(x.c_str()); +} + +bool String::hasSuffixIgnoreCase(const char *x) const { + assert(x != nullptr); + // Compare x with the end of _str. + const uint32 x_size = strlen(x); + if (x_size > _size) + return false; + const char *y = c_str() + _size - x_size; + while (*x && tolower(*x) == tolower(*y)) { + ++x; + ++y; + } + // It's a suffix, if and only if all letters in x are 'used up' before + // _str ends. + return *x == 0; +} + bool String::contains(const String &x) const { return strstr(c_str(), x.c_str()) != NULL; } diff --git a/common/str.h b/common/str.h index fd77fa90c84..69c343ad7dd 100644 --- a/common/str.h +++ b/common/str.h @@ -154,9 +154,13 @@ public: bool hasSuffix(const String &x) const; bool hasSuffix(const char *x) const; + bool hasSuffixIgnoreCase(const String &x) const; + bool hasSuffixIgnoreCase(const char *x) const; bool hasPrefix(const String &x) const; bool hasPrefix(const char *x) const; + bool hasPrefixIgnoreCase(const String &x) const; + bool hasPrefixIgnoreCase(const char *x) const; bool contains(const String &x) const; bool contains(const char *x) const; diff --git a/gui/debugger.cpp b/gui/debugger.cpp index ce4661e9cbb..fb03b578922 100644 --- a/gui/debugger.cpp +++ b/gui/debugger.cpp @@ -470,7 +470,7 @@ bool Debugger::tabComplete(const char *input, Common::String &completion) const CommandsMap::const_iterator i, e = _cmds.end(); for (i = _cmds.begin(); i != e; ++i) { - if (i->_key.hasPrefix(input)) { + if (i->_key.hasPrefixIgnoreCase(input)) { uint commandlen = i->_key.size(); if (commandlen == inputlen) { // perfect match, so no tab completion possible return false;