aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Bouclet2018-04-27 19:34:34 +0200
committerBastien Bouclet2018-04-30 20:31:44 +0200
commit7382af32be416e99afe077e822c13535a258c12a (patch)
tree132773d47f715aa7430b70c88a19cd1994d2c6eb
parent0e9dc861506ac3d89467c34b18b5cd11df63eb53 (diff)
downloadscummvm-rg350-7382af32be416e99afe077e822c13535a258c12a.tar.gz
scummvm-rg350-7382af32be416e99afe077e822c13535a258c12a.tar.bz2
scummvm-rg350-7382af32be416e99afe077e822c13535a258c12a.zip
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.
-rw-r--r--common/str.cpp37
-rw-r--r--common/str.h4
-rw-r--r--gui/debugger.cpp2
3 files changed, 42 insertions, 1 deletions
diff --git a/common/str.cpp b/common/str.cpp
index 7d40aebf94..077a493fd0 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 cf7fc34f6b..7a1706b7e1 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 ce4661e9cb..fb03b57892 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;