mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-01 03:48:43 +00:00
(svn r21344) -Feature [FS#4214]: Natural sorting of strings using ICU.
This commit is contained in:
parent
4b944cb13e
commit
75f86a7a21
@ -157,7 +157,7 @@ static int CDECL EngineNameSorter(const EngineID *a, const EngineID *b)
|
||||
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);
|
||||
|
@ -134,7 +134,7 @@ static int CDECL CargoSpecNameSorter(const CargoSpec * const *a, const CargoSpec
|
||||
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);
|
||||
|
@ -160,7 +160,7 @@ private:
|
||||
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;
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ static int CDECL IndustryTypeNameSorter(const IndustryType *a, const IndustryTyp
|
||||
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 @@ protected:
|
||||
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 */
|
||||
|
@ -266,7 +266,7 @@ class NetworkContentListWindow : public QueryStringBaseWindow, ContentCallback {
|
||||
/** 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 @@ class NetworkContentListWindow : public QueryStringBaseWindow, ContentCallback {
|
||||
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;
|
||||
|
@ -279,7 +279,7 @@ protected:
|
||||
/** 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).
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1201,7 +1201,7 @@ private:
|
||||
/** 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;
|
||||
|
@ -92,7 +92,7 @@ struct SignList {
|
||||
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);
|
||||
}
|
||||
|
@ -700,7 +700,7 @@ private:
|
||||
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 */
|
||||
|
@ -766,7 +766,7 @@ static int CDECL VehicleNameSorter(const Vehicle * const *a, const Vehicle * con
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user