[Scummvm-git-logs] scummvm case-insensitive-tab-completion -> ecf6b2bf4d3e5e9ae3600d996d18a45d3075f1b8

bgK bastien.bouclet at gmail.com
Fri Apr 27 19:37:14 CEST 2018


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
ecf6b2bf4d GUI: Make the tab completion case insensitive in the debug console


Commit: ecf6b2bf4d3e5e9ae3600d996d18a45d3075f1b8
    https://github.com/scummvm/scummvm/commit/ecf6b2bf4d3e5e9ae3600d996d18a45d3075f1b8
Author: Bastien Bouclet (bastien.bouclet at gmail.com)
Date: 2018-04-27T19:34:34+02:00

Commit Message:
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.

Changed paths:
    common/str.cpp
    common/str.h
    gui/debugger.cpp


diff --git a/common/str.cpp b/common/str.cpp
index 7d40aeb..077a493 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 cf7fc34..7a1706b 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 ce4661e..fb03b57 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;





More information about the Scummvm-git-logs mailing list