From 861b9bc85e8d6e418ca695d2f3eee74ef9edbcdf Mon Sep 17 00:00:00 2001 From: frosch Date: Tue, 18 Nov 2014 20:12:42 +0000 Subject: (svn r27063) -Fix [FS#6172]: Some lists did not use natural string sorting. --- src/newgrf_config.cpp | 2 +- src/station_gui.cpp | 7 +++++-- src/strings.cpp | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index 18f47b64a..bd95373d9 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -715,7 +715,7 @@ static int CDECL GRFSorter(GRFConfig * const *p1, GRFConfig * const *p2) const GRFConfig *c1 = *p1; const GRFConfig *c2 = *p2; - return strcasecmp(c1->GetName(), c2->GetName()); + return strnatcmp(c1->GetName(), c2->GetName()); } /** diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 92b98dd39..b5e705f73 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -19,6 +19,7 @@ #include "cargotype.h" #include "station_gui.h" #include "strings_func.h" +#include "string_func.h" #include "window_func.h" #include "viewport_func.h" #include "widgets/dropdown_func.h" @@ -222,7 +223,9 @@ protected: GetString(buf_cache, STR_STATION_NAME, lastof(buf_cache)); } - return strcmp(buf, buf_cache); + int r = strnatcmp(buf, buf_cache); // Sort by name (natural sorting). + if (r == 0) return (*a)->index - (*b)->index; + return r; } /** Sort stations by their type */ @@ -1186,7 +1189,7 @@ bool CargoSorter::SortStation(StationID st1, StationID st2) const SetDParam(0, st2); GetString(buf2, STR_STATION_NAME, lastof(buf2)); - int res = strcmp(buf1, buf2); + int res = strnatcmp(buf1, buf2); // Sort by name (natural sorting). if (res == 0) { return this->SortId(st1, st2); } else { diff --git a/src/strings.cpp b/src/strings.cpp index 90ead8559..8ce2fde07 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -1864,7 +1864,7 @@ int CDECL StringIDSorter(const StringID *a, const StringID *b) GetString(stra, *a, lastof(stra)); GetString(strb, *b, lastof(strb)); - return strcmp(stra, strb); + return strnatcmp(stra, strb); } /** -- cgit v1.2.3-54-g00ecf