changeset 16614:1111794047a4 draft

(svn r21344) -Feature [FS#4214]: Natural sorting of strings using ICU.
author terkhen <terkhen@openttd.org>
date Sat, 27 Nov 2010 22:52:12 +0000
parents 4527392bba00
children 4cca4a42c19f
files src/build_vehicle_gui.cpp src/cargotype.cpp src/group_gui.cpp src/industry_gui.cpp src/network/network_content_gui.cpp src/network/network_gui.cpp src/newgrf_gui.cpp src/signs_gui.cpp src/town_gui.cpp src/vehicle_gui.cpp
diffstat 10 files changed, 12 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -157,7 +157,7 @@
 		GetString(last_name[1], STR_ENGINE_NAME, lastof(last_name[1]));
 	}
 
-	int r = strcmp(last_name[0], last_name[1]); // sort by name
+	int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting).
 
 	/* Use EngineID to sort instead since we want consistent sorting */
 	if (r == 0) return EngineNumberSorter(a, b);
--- a/src/cargotype.cpp
+++ b/src/cargotype.cpp
@@ -134,7 +134,7 @@
 	GetString(a_name, (*a)->name, lastof(a_name));
 	GetString(b_name, (*b)->name, lastof(b_name));
 
-	int res = strcmp(a_name, b_name);
+	int res = strnatcmp(a_name, b_name); // Sort by name (natural sorting).
 
 	/* If the names are equal, sort by cargo bitnum. */
 	return (res != 0) ? res : ((*a)->bitnum - (*b)->bitnum);
--- a/src/group_gui.cpp
+++ b/src/group_gui.cpp
@@ -160,7 +160,7 @@
 			GetString(last_name[1], STR_GROUP_NAME, lastof(last_name[1]));
 		}
 
-		int r = strcmp(last_name[0], last_name[1]); // sort by name
+		int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting).
 		if (r == 0) return (*a)->index - (*b)->index;
 		return r;
 	}
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -120,7 +120,7 @@
 	SetDParam(0, indsp2->name);
 	GetString(industry_name[1], STR_JUST_STRING, lastof(industry_name[1]));
 
-	int r = strcmp(industry_name[0], industry_name[1]);
+	int r = strnatcmp(industry_name[0], industry_name[1]); // Sort by name (natural sorting).
 
 	/* If the names are equal, sort by industry type. */
 	return (r != 0) ? r : (*a - *b);
@@ -1137,7 +1137,7 @@
 			GetString(buf_cache, STR_INDUSTRY_NAME, lastof(buf_cache));
 		}
 
-		return strcmp(buf, buf_cache);
+		return strnatcmp(buf, buf_cache); // Sort by name (natural sorting).
 	}
 
 	/** Sort industries by type and name */
--- a/src/network/network_content_gui.cpp
+++ b/src/network/network_content_gui.cpp
@@ -266,7 +266,7 @@
 	/** Sort content by name. */
 	static int CDECL NameSorter(const ContentInfo * const *a, const ContentInfo * const *b)
 	{
-		return strcasecmp((*a)->name, (*b)->name);
+		return strnatcmp((*a)->name, (*b)->name); // Sort by name (natural sorting).
 	}
 
 	/** Sort content by type. */
@@ -278,7 +278,7 @@
 			char b_str[64];
 			GetString(a_str, STR_CONTENT_TYPE_BASE_GRAPHICS + (*a)->type - CONTENT_TYPE_BASE_GRAPHICS, lastof(a_str));
 			GetString(b_str, STR_CONTENT_TYPE_BASE_GRAPHICS + (*b)->type - CONTENT_TYPE_BASE_GRAPHICS, lastof(b_str));
-			r = strcasecmp(a_str, b_str);
+			r = strnatcmp(a_str, b_str);
 		}
 		if (r == 0) r = NameSorter(a, b);
 		return r;
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -279,7 +279,7 @@
 	/** Sort servers by name. */
 	static int CDECL NGameNameSorter(NetworkGameList * const *a, NetworkGameList * const *b)
 	{
-		return strcasecmp((*a)->info.server_name, (*b)->info.server_name);
+		return strnatcmp((*a)->info.server_name, (*b)->info.server_name); // Sort by name (natural sorting).
 	}
 
 	/**
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -1201,7 +1201,7 @@
 	/** Sort grfs by name. */
 	static int CDECL NameSorter(const GRFConfig * const *a, const GRFConfig * const *b)
 	{
-		int i = strcasecmp((*a)->GetName(), (*b)->GetName());
+		int i = strnatcmp((*a)->GetName(), (*b)->GetName()); // Sort by name (natural sorting).
 		if (i != 0) return i;
 
 		i = (*a)->version - (*b)->version;
--- a/src/signs_gui.cpp
+++ b/src/signs_gui.cpp
@@ -92,7 +92,7 @@
 			GetString(buf_cache, STR_SIGN_NAME, lastof(buf_cache));
 		}
 
-		int r = strcasecmp(buf, buf_cache);
+		int r = strnatcmp(buf, buf_cache); // Sort by name (natural sorting).
 
 		return r != 0 ? r : ((*a)->index - (*b)->index);
 	}
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -700,7 +700,7 @@
 			GetString(buf_cache, STR_TOWN_NAME, lastof(buf_cache));
 		}
 
-		return strcmp(buf, buf_cache);
+		return strnatcmp(buf, buf_cache); // Sort by name (natural sorting).
 	}
 
 	/** Sort by population */
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -766,7 +766,7 @@
 		GetString(last_name[1], STR_VEHICLE_NAME, lastof(last_name[1]));
 	}
 
-	int r = strcmp(last_name[0], last_name[1]);
+	int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting).
 	return (r != 0) ? r : VehicleNumberSorter(a, b);
 }