[Scummvm-git-logs] scummvm master -> a08dc72eabcba0cd5f524bb0b6a06bca6e6acd18

sev- sev at scummvm.org
Fri Apr 24 08:54:05 UTC 2020


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

Summary:
0b00d71643 COMMON: Add methods for dictionary string comparison
9bea9fd5cf GUI: Sort games by dictionary, ignoring English articles
a08dc72eab COMMON: Skip "an " in dictionary sort


Commit: 0b00d71643c36c08aec8da4d30abe1b572bbb7a6
    https://github.com/scummvm/scummvm/commit/0b00d71643c36c08aec8da4d30abe1b572bbb7a6
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-04-24T10:54:00+02:00

Commit Message:
COMMON: Add methods for dictionary string comparison

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


diff --git a/common/str.cpp b/common/str.cpp
index d8e384760b..f7cae24bc8 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -895,6 +895,15 @@ int String::compareToIgnoreCase(const char *x) const {
 	return scumm_stricmp(c_str(), x);
 }
 
+int String::compareDictionary(const String &x) const {
+	return compareDictionary(x.c_str());
+}
+
+int String::compareDictionary(const char *x) const {
+	assert(x != nullptr);
+	return scumm_compareDictionary(c_str(), x);
+}
+
 #pragma mark -
 
 String operator+(const String &x, const String &y) {
@@ -1284,6 +1293,20 @@ int scumm_strnicmp(const char *s1, const char *s2, uint n) {
 	return l1 - l2;
 }
 
+const char *scumm_skipArticle(const char *s1) {
+	int o1 = 0;
+	if (!scumm_strnicmp(s1, "the ", 4))
+		o1 = 4;
+	else if (!scumm_strnicmp(s1, "a ", 2))
+		o1 = 2;
+
+	return &s1[o1];
+}
+
+int scumm_compareDictionary(const char *s1, const char *s2) {
+	return scumm_stricmp(scumm_skipArticle(s1), scumm_skipArticle(s2));
+}
+
 //  Portable implementation of strdup.
 char *scumm_strdup(const char *in) {
 	const size_t len = strlen(in) + 1;
diff --git a/common/str.h b/common/str.h
index 101890279a..c19b2ef699 100644
--- a/common/str.h
+++ b/common/str.h
@@ -156,6 +156,8 @@ public:
 	bool equalsIgnoreCase(const char *x) const;
 	int compareTo(const char *x) const;             // strcmp clone
 	int compareToIgnoreCase(const char *x) const;   // stricmp clone
+	int compareDictionary(const String &x) const;
+	int compareDictionary(const char *x) const;
 
 	bool hasSuffix(const String &x) const;
 	bool hasSuffix(const char *x) const;
@@ -340,7 +342,7 @@ public:
 	size_t findLastOf(const String &chars, size_t pos = npos) const {
 		return findLastOf(chars.c_str(), pos);
 	}
- 
+
 	/** Find first character in the string that's not the specified character */
 	size_t findFirstNotOf(char c, size_t pos = 0) const;
 
@@ -563,4 +565,7 @@ extern int scumm_stricmp(const char *s1, const char *s2);
 extern int scumm_strnicmp(const char *s1, const char *s2, uint n);
 extern char *scumm_strdup(const char *in);
 
+extern int scumm_compareDictionary(const char *s1, const char *s2);
+extern const char *scumm_skipArticle(const char *s1);
+
 #endif


Commit: 9bea9fd5cf83c708c90fc3283251f88caf6075b8
    https://github.com/scummvm/scummvm/commit/9bea9fd5cf83c708c90fc3283251f88caf6075b8
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-04-24T10:54:00+02:00

Commit Message:
GUI: Sort games by dictionary, ignoring English articles

Changed paths:
    gui/launcher.cpp
    gui/widgets/list.cpp
    gui/widgets/list.h


diff --git a/gui/launcher.cpp b/gui/launcher.cpp
index 4f11d1e9cd..ae07aeb89d 100644
--- a/gui/launcher.cpp
+++ b/gui/launcher.cpp
@@ -190,6 +190,7 @@ void LauncherDialog::build() {
 	// Add list with game titles
 	_list = new ListWidget(this, "Launcher.GameList", nullptr, kListSearchCmd);
 	_list->setEditable(false);
+	_list->enableDictionarySelect(true);
 	_list->setNumberingMode(kListNumberingOff);
 
 	// Populate the list
@@ -292,7 +293,7 @@ void LauncherDialog::updateListing() {
 			// Insert the game into the launcher list
 			int pos = 0, size = l.size();
 
-			while (pos < size && (scumm_stricmp(description.c_str(), l[pos].c_str()) > 0))
+			while (pos < size && (scumm_compareDictionary(description.c_str(), l[pos].c_str()) > 0))
 				pos++;
 
 			color = ThemeEngine::kFontColorNormal;
diff --git a/gui/widgets/list.cpp b/gui/widgets/list.cpp
index 8bdc002a8e..759622a329 100644
--- a/gui/widgets/list.cpp
+++ b/gui/widgets/list.cpp
@@ -59,6 +59,7 @@ ListWidget::ListWidget(Dialog *boss, const String &name, const char *tooltip, ui
 
 	_quickSelect = true;
 	_editColor = ThemeEngine::kFontColorNormal;
+	_dictionarySelect = false;
 
 	_lastRead = -1;
 }
@@ -89,6 +90,7 @@ ListWidget::ListWidget(Dialog *boss, int x, int y, int w, int h, const char *too
 
 	_quickSelect = true;
 	_editColor = ThemeEngine::kFontColorNormal;
+	_dictionarySelect = false;
 
 	_lastRead = -1;
 }
@@ -296,8 +298,12 @@ int ListWidget::findItem(int x, int y) const {
 		return -1;
 }
 
-static int matchingCharsIgnoringCase(const char *x, const char *y, bool &stop) {
+static int matchingCharsIgnoringCase(const char *x, const char *y, bool &stop, bool dictionary) {
 	int match = 0;
+	if (dictionary) {
+		x = scumm_skipArticle(x);
+		y = scumm_skipArticle(y);
+	}
 	while (*x && *y && tolower(*x) == tolower(*y)) {
 		++x;
 		++y;
@@ -333,7 +339,7 @@ bool ListWidget::handleKeyDown(Common::KeyState state) {
 			int bestMatch = 0;
 			bool stop;
 			for (StringArray::const_iterator i = _list.begin(); i != _list.end(); ++i) {
-				const int match = matchingCharsIgnoringCase(i->c_str(), _quickSelectStr.c_str(), stop);
+				const int match = matchingCharsIgnoringCase(i->c_str(), _quickSelectStr.c_str(), stop, _dictionarySelect);
 				if (match > bestMatch || stop) {
 					_selectedItem = newSelectedItem;
 					bestMatch = match;
diff --git a/gui/widgets/list.h b/gui/widgets/list.h
index f915b9b0f9..4368686845 100644
--- a/gui/widgets/list.h
+++ b/gui/widgets/list.h
@@ -79,6 +79,7 @@ protected:
 
 	String			_filter;
 	bool			_quickSelect;
+	bool			_dictionarySelect;
 
 	uint32			_cmd;
 
@@ -113,6 +114,8 @@ public:
 	void enableQuickSelect(bool enable) 		{ _quickSelect = enable; }
 	String getQuickSelectString() const 		{ return _quickSelectStr; }
 
+	void enableDictionarySelect(bool enable)	{ _dictionarySelect = enable; }
+
 	bool isEditable() const						{ return _editable; }
 	void setEditable(bool editable)				{ _editable = editable; }
 	void setEditColor(ThemeEngine::FontColor color) { _editColor = color; }


Commit: a08dc72eabcba0cd5f524bb0b6a06bca6e6acd18
    https://github.com/scummvm/scummvm/commit/a08dc72eabcba0cd5f524bb0b6a06bca6e6acd18
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-04-24T10:54:00+02:00

Commit Message:
COMMON: Skip "an " in dictionary sort

Changed paths:
    common/str.cpp


diff --git a/common/str.cpp b/common/str.cpp
index f7cae24bc8..068f4ac690 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -1299,6 +1299,8 @@ const char *scumm_skipArticle(const char *s1) {
 		o1 = 4;
 	else if (!scumm_strnicmp(s1, "a ", 2))
 		o1 = 2;
+	else if (!scumm_strnicmp(s1, "an ", 3))
+		o1 = 3;
 
 	return &s1[o1];
 }




More information about the Scummvm-git-logs mailing list