summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2012-01-01 22:32:26 +0000
committerrubidium <rubidium@openttd.org>2012-01-01 22:32:26 +0000
commit9a921fd0ae29e63de75524fa2f41a7beac11184d (patch)
tree789caab4f54c8f55d4e275b7ffa030f74b0caf48 /src
parentcb414b09d2e803a9492781f9d23cd84b9890cc55 (diff)
downloadopenttd-9a921fd0ae29e63de75524fa2f41a7beac11184d.tar.xz
(svn r23709) -Feature-ish: try harder to sort text instead of fancy characters in the server names
Diffstat (limited to 'src')
-rw-r--r--src/network/network_gui.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index 649f809ae..539087ff8 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -244,10 +244,24 @@ protected:
this->vscroll->SetCount(this->servers.Length());
}
+ /**
+ * Skip some of the 'garbage' in the string that we don't want to use
+ * to sort on. This way the alphabetical sorting will work better as
+ * we would be actually using those characters instead of some other
+ * characters such as spaces and tildes at the begin of the name.
+ * @param str The string to skip the initial garbage of.
+ * @return The string with the garbage skipped.
+ */
+ static const char *SkipGarbage(const char *str)
+ {
+ while (*str != '\0' && (*str < 'A' || IsInsideMM(*str, '[', '`' + 1) || IsInsideMM(*str, '{', '~' + 1))) str++;
+ return str;
+ }
+
/** Sort servers by name. */
static int CDECL NGameNameSorter(NetworkGameList * const *a, NetworkGameList * const *b)
{
- int r = strnatcmp((*a)->info.server_name, (*b)->info.server_name); // Sort by name (natural sorting).
+ int r = strnatcmp(SkipGarbage((*a)->info.server_name), SkipGarbage((*b)->info.server_name)); // Sort by name (natural sorting).
return r == 0 ? (*a)->address.CompareTo((*b)->address) : r;
}