Changeset - r27193:e816892ba57b
[Not reviewed]
master
0 22 0
Rubidium - 19 months ago 2023-04-27 13:39:10
rubidium@openttd.org
Codechange: replace strnatcmp with C++ string capable version
22 files changed with 47 insertions and 54 deletions:
0 comments (0 inline, 0 general)
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -153,13 +153,13 @@ static bool EngineNameSorter(const GUIEn
 
	if (b.engine_id != _last_engine[1]) {
 
		_last_engine[1] = b.engine_id;
 
		SetDParam(0, PackEngineNameDParam(b.engine_id, EngineNameContext::PurchaseList));
 
		GetString(last_name[1], STR_ENGINE_NAME, lastof(last_name[1]));
 
	}
 

	
 
	int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting).
 
	int r = StrNaturalCompare(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);
 
	return _engine_sort_direction ? r > 0 : r < 0;
 
}
 

	
src/cargotype.cpp
Show inline comments
 
@@ -153,19 +153,16 @@ SpriteID CargoSpec::GetCargoIcon() const
 
std::vector<const CargoSpec *> _sorted_cargo_specs;   ///< Cargo specifications sorted alphabetically by name.
 
span<const CargoSpec *> _sorted_standard_cargo_specs; ///< Standard cargo specifications sorted alphabetically by name.
 

	
 
/** Sort cargo specifications by their name. */
 
static bool CargoSpecNameSorter(const CargoSpec * const &a, const CargoSpec * const &b)
 
{
 
	static char a_name[64];
 
	static char b_name[64];
 
	std::string a_name = GetString(a->name);
 
	std::string b_name = GetString(b->name);
 

	
 
	GetString(a_name, a->name, lastof(a_name));
 
	GetString(b_name, b->name, lastof(b_name));
 

	
 
	int res = strnatcmp(a_name, b_name); // Sort by name (natural sorting).
 
	int res = StrNaturalCompare(a_name, b_name); // Sort by name (natural sorting).
 

	
 
	/* If the names are equal, sort by cargo bitnum. */
 
	return (res != 0) ? res < 0 : (a->bitnum < b->bitnum);
 
}
 

	
 
/** Sort cargo specifications by their cargo class. */
src/company_gui.cpp
Show inline comments
 
@@ -732,13 +732,13 @@ private:
 
				if (b != last_group[1]) {
 
					last_group[1] = b;
 
					SetDParam(0, b->index);
 
					GetString(last_name[1], STR_GROUP_NAME, lastof(last_name[1]));
 
				}
 

	
 
				int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting).
 
				int r = StrNaturalCompare(last_name[0], last_name[1]); // Sort by name (natural sorting).
 
				if (r == 0) return a->index < b->index;
 
				return r < 0;
 
			});
 

	
 
			AddChildren(&list, INVALID_GROUP, 0);
 
		}
src/fios.cpp
Show inline comments
 
@@ -55,13 +55,13 @@ bool FiosItem::operator< (const FiosItem
 
{
 
	int r = false;
 

	
 
	if ((_savegame_sort_order & SORT_BY_NAME) == 0 && (*this).mtime != other.mtime) {
 
		r = (*this).mtime - other.mtime;
 
	} else {
 
		r = strnatcmp((*this).title, other.title);
 
		r = StrNaturalCompare((*this).title, other.title);
 
	}
 
	if (r == 0) return false;
 
	return (_savegame_sort_order & SORT_DESCENDING) ? r > 0 : r < 0;
 
}
 

	
 
/**
src/group_gui.cpp
Show inline comments
 
@@ -188,13 +188,13 @@ private:
 
			if (b != last_group[1]) {
 
				last_group[1] = b;
 
				SetDParam(0, b->index);
 
				GetString(last_name[1], STR_GROUP_NAME, lastof(last_name[1]));
 
			}
 

	
 
			int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting).
 
			int r = StrNaturalCompare(last_name[0], last_name[1]); // Sort by name (natural sorting).
 
			if (r == 0) return a->index < b->index;
 
			return r < 0;
 
		});
 

	
 
		AddChildren(&list, INVALID_GROUP, 0);
 

	
src/industry_gui.cpp
Show inline comments
 
@@ -199,13 +199,13 @@ static bool IndustryTypeNameSorter(const
 
	const IndustrySpec *indsp1 = GetIndustrySpec(a);
 
	GetString(industry_name[0], indsp1->name, lastof(industry_name[0]));
 

	
 
	const IndustrySpec *indsp2 = GetIndustrySpec(b);
 
	GetString(industry_name[1], indsp2->name, lastof(industry_name[1]));
 

	
 
	int r = strnatcmp(industry_name[0], industry_name[1]); // Sort by name (natural sorting).
 
	int r = StrNaturalCompare(industry_name[0], industry_name[1]); // Sort by name (natural sorting).
 

	
 
	/* If the names are equal, sort by industry type. */
 
	return (r != 0) ? r < 0 : (a < b);
 
}
 

	
 
/**
 
@@ -1495,13 +1495,13 @@ protected:
 
		return percentage / produced_cargo_count;
 
	}
 

	
 
	/** Sort industries by name */
 
	static bool IndustryNameSorter(const Industry * const &a, const Industry * const &b)
 
	{
 
		int r = strnatcmp(a->GetCachedName(), b->GetCachedName()); // Sort by name (natural sorting).
 
		int r = StrNaturalCompare(a->GetCachedName(), b->GetCachedName()); // Sort by name (natural sorting).
 
		if (r == 0) return a->index < b->index;
 
		return r < 0;
 
	}
 

	
 
	/** Sort industries by type and name */
 
	static bool IndustryTypeSorter(const Industry * const &a, const Industry * const &b)
src/network/network_content_gui.cpp
Show inline comments
 
@@ -429,21 +429,21 @@ class NetworkContentListWindow : public 
 
		this->ScrollToSelected();
 
	}
 

	
 
	/** Sort content by name. */
 
	static bool NameSorter(const ContentInfo * const &a, const ContentInfo * const &b)
 
	{
 
		return strnatcmp(a->name.c_str(), b->name.c_str(), true) < 0; // Sort by name (natural sorting).
 
		return StrNaturalCompare(a->name, b->name, true) < 0; // Sort by name (natural sorting).
 
	}
 

	
 
	/** Sort content by type. */
 
	static bool TypeSorter(const ContentInfo * const &a, const ContentInfo * const &b)
 
	{
 
		int r = 0;
 
		if (a->type != b->type) {
 
			r = strnatcmp(content_type_strs[a->type], content_type_strs[b->type]);
 
			r = StrNaturalCompare(content_type_strs[a->type], content_type_strs[b->type]);
 
		}
 
		if (r == 0) return NameSorter(a, b);
 
		return r < 0;
 
	}
 

	
 
	/** Sort content by state. */
src/network/network_gui.cpp
Show inline comments
 
@@ -286,13 +286,13 @@ protected:
 
		this->UpdateListPos();
 
	}
 

	
 
	/** Sort servers by name. */
 
	static bool NGameNameSorter(NetworkGameList * const &a, NetworkGameList * const &b)
 
	{
 
		int r = strnatcmp(a->info.server_name.c_str(), b->info.server_name.c_str(), true); // Sort by name (natural sorting).
 
		int r = StrNaturalCompare(a->info.server_name, b->info.server_name, true); // Sort by name (natural sorting).
 
		if (r == 0) r = a->connection_string.compare(b->connection_string);
 

	
 
		return r < 0;
 
	}
 

	
 
	/**
src/newgrf_config.cpp
Show inline comments
 
@@ -667,13 +667,13 @@ bool GRFFileScanner::AddFile(const std::
 
 * @param c1 the first GRFConfig *
 
 * @param c2 the second GRFConfig *
 
 * @return true if the name of first NewGRF is before the name of the second.
 
 */
 
static bool GRFSorter(GRFConfig * const &c1, GRFConfig * const &c2)
 
{
 
	return strnatcmp(c1->GetName(), c2->GetName()) < 0;
 
	return StrNaturalCompare(c1->GetName(), c2->GetName()) < 0;
 
}
 

	
 
/**
 
 * Really perform the scan for all NewGRFs.
 
 * @param callback The callback to call after the scanning is complete.
 
 */
src/newgrf_gui.cpp
Show inline comments
 
@@ -1425,13 +1425,13 @@ struct NewGRFWindow : public Window, New
 
	}
 

	
 
private:
 
	/** Sort grfs by name. */
 
	static bool NameSorter(const GRFConfig * const &a, const GRFConfig * const &b)
 
	{
 
		int i = strnatcmp(a->GetName(), b->GetName(), true); // Sort by name (natural sorting).
 
		int i = StrNaturalCompare(a->GetName(), b->GetName(), true); // Sort by name (natural sorting).
 
		if (i != 0) return i < 0;
 

	
 
		i = a->version - b->version;
 
		if (i != 0) return i < 0;
 

	
 
		return memcmp(a->ident.md5sum, b->ident.md5sum, lengthof(b->ident.md5sum)) < 0;
src/os/macosx/string_osx.cpp
Show inline comments
 
@@ -319,21 +319,21 @@ void MacOSSetCurrentLocaleName(const cha
 
 * Compares two strings using case insensitive natural sort.
 
 *
 
 * @param s1 First string to compare.
 
 * @param s2 Second string to compare.
 
 * @return 1 if s1 < s2, 2 if s1 == s2, 3 if s1 > s2, or 0 if not supported by the OS.
 
 */
 
int MacOSStringCompare(const char *s1, const char *s2)
 
int MacOSStringCompare(std::string_view s1, std::string_view s2)
 
{
 
	static bool supported = MacOSVersionIsAtLeast(10, 5, 0);
 
	if (!supported) return 0;
 

	
 
	CFStringCompareFlags flags = kCFCompareCaseInsensitive | kCFCompareNumerically | kCFCompareLocalized | kCFCompareWidthInsensitive | kCFCompareForcedOrdering;
 

	
 
	CFAutoRelease<CFStringRef> cf1(CFStringCreateWithCString(kCFAllocatorDefault, s1, kCFStringEncodingUTF8));
 
	CFAutoRelease<CFStringRef> cf2(CFStringCreateWithCString(kCFAllocatorDefault, s2, kCFStringEncodingUTF8));
 
	CFAutoRelease<CFStringRef> cf1(CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8 *)s1.data(), s1.size(), kCFStringEncodingUTF8, false));
 
	CFAutoRelease<CFStringRef> cf2(CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8 *)s2.data(), s2.size(), kCFStringEncodingUTF8, false));
 

	
 
	/* If any CFString could not be created (e.g., due to UTF8 invalid chars), return OS unsupported functionality */
 
	if (cf1 == nullptr || cf2 == nullptr) return 0;
 

	
 
	return (int)CFStringCompareWithOptionsAndLocale(cf1.get(), cf2.get(), CFRangeMake(0, CFStringGetLength(cf1.get())), flags, _osx_locale.get()) + 2;
 
}
src/os/macosx/string_osx.h
Show inline comments
 
@@ -80,11 +80,11 @@ public:
 
		}
 
	}
 
};
 

	
 
void MacOSResetScriptCache(FontSize size);
 
void MacOSSetCurrentLocaleName(const char *iso_code);
 
int MacOSStringCompare(const char *s1, const char *s2);
 
int MacOSStringCompare(std::string_view s1, std::string_view s2);
 

	
 
void MacOSRegisterExternalFont(const char *file_path);
 

	
 
#endif /* STRING_OSX_H */
src/os/windows/win32.cpp
Show inline comments
 
@@ -564,13 +564,13 @@ void Win32SetCurrentLocaleName(const cha
 
		}
 
	}
 

	
 
	MultiByteToWideChar(CP_UTF8, 0, iso, -1, _cur_iso_locale, lengthof(_cur_iso_locale));
 
}
 

	
 
int OTTDStringCompare(const char *s1, const char *s2)
 
int OTTDStringCompare(std::string_view s1, std::string_view s2)
 
{
 
	typedef int (WINAPI *PFNCOMPARESTRINGEX)(LPCWSTR, DWORD, LPCWCH, int, LPCWCH, int, LPVOID, LPVOID, LPARAM);
 
	static PFNCOMPARESTRINGEX _CompareStringEx = nullptr;
 
	static bool first_time = true;
 

	
 
#ifndef SORT_DIGITSASNUMBERS
 
@@ -585,21 +585,21 @@ int OTTDStringCompare(const char *s1, co
 
		_CompareStringEx = _kernel32.GetProcAddress("CompareStringEx");
 
		first_time = false;
 
	}
 

	
 
	if (_CompareStringEx != nullptr) {
 
		/* CompareStringEx takes UTF-16 strings, even in ANSI-builds. */
 
		int len_s1 = MultiByteToWideChar(CP_UTF8, 0, s1, -1, nullptr, 0);
 
		int len_s2 = MultiByteToWideChar(CP_UTF8, 0, s2, -1, nullptr, 0);
 
		int len_s1 = MultiByteToWideChar(CP_UTF8, 0, s1.data(), (int)s1.size(), nullptr, 0);
 
		int len_s2 = MultiByteToWideChar(CP_UTF8, 0, s2.data(), (int)s2.size(), nullptr, 0);
 

	
 
		if (len_s1 != 0 && len_s2 != 0) {
 
			std::wstring str_s1(len_s1, L'\0'); // len includes terminating null
 
			std::wstring str_s2(len_s2, L'\0');
 

	
 
			MultiByteToWideChar(CP_UTF8, 0, s1, -1, str_s1.data(), len_s1);
 
			MultiByteToWideChar(CP_UTF8, 0, s2, -1, str_s2.data(), len_s2);
 
			MultiByteToWideChar(CP_UTF8, 0, s1.data(), (int)s1.size(), str_s1.data(), len_s1);
 
			MultiByteToWideChar(CP_UTF8, 0, s2.data(), (int)s2.size(), str_s2.data(), len_s2);
 

	
 
			int result = _CompareStringEx(_cur_iso_locale, LINGUISTIC_IGNORECASE | SORT_DIGITSASNUMBERS, str_s1.c_str(), -1, str_s2.c_str(), -1, nullptr, nullptr, 0);
 
			if (result != 0) return result;
 
		}
 
	}
 

	
src/os/windows/win32.h
Show inline comments
 
@@ -56,9 +56,9 @@ private:
 
};
 

	
 
char *convert_from_fs(const wchar_t *name, char *utf8_buf, size_t buflen);
 
wchar_t *convert_to_fs(const std::string_view name, wchar_t *utf16_buf, size_t buflen);
 

	
 
void Win32SetCurrentLocaleName(const char *iso_code);
 
int OTTDStringCompare(const char *s1, const char *s2);
 
int OTTDStringCompare(std::string_view s1, std::string_view s2);
 

	
 
#endif /* WIN32_H */
src/signs_gui.cpp
Show inline comments
 
@@ -44,13 +44,13 @@ struct SignList {
 
	typedef GUIList<const Sign *, StringFilter &> GUISignList;
 

	
 
	GUISignList signs;
 

	
 
	StringFilter string_filter;                                       ///< The match string to be used when the GUIList is (re)-sorted.
 
	static bool match_case;                                           ///< Should case sensitive matching be used?
 
	static char default_name[64];                                     ///< Default sign name, used if Sign::name is nullptr.
 
	static std::string default_name;                                  ///< Default sign name, used if Sign::name is nullptr.
 

	
 
	/**
 
	 * Creates a SignList with filtering disabled by default.
 
	 */
 
	SignList() : string_filter(&match_case)
 
	{
 
@@ -76,16 +76,16 @@ struct SignList {
 
	static bool SignNameSorter(const Sign * const &a, const Sign * const &b)
 
	{
 
		/* Signs are very very rarely using the default text, but there can also be
 
		 * a lot of them. Therefore a worthwhile performance gain can be made by
 
		 * directly comparing Sign::name instead of going through the string
 
		 * system for each comparison. */
 
		const char *a_name = a->name.empty() ? SignList::default_name : a->name.c_str();
 
		const char *b_name = b->name.empty() ? SignList::default_name : b->name.c_str();
 
		const std::string &a_name = a->name.empty() ? SignList::default_name : a->name;
 
		const std::string &b_name = b->name.empty() ? SignList::default_name : b->name;
 

	
 
		int r = strnatcmp(a_name, b_name); // Sort by name (natural sorting).
 
		int r = StrNaturalCompare(a_name, b_name); // Sort by name (natural sorting).
 

	
 
		return r != 0 ? r < 0 : (a->index < b->index);
 
	}
 

	
 
	void SortSignsList()
 
	{
 
@@ -93,16 +93,16 @@ struct SignList {
 
	}
 

	
 
	/** Filter sign list by sign name */
 
	static bool CDECL SignNameFilter(const Sign * const *a, StringFilter &filter)
 
	{
 
		/* Same performance benefit as above for sorting. */
 
		const char *a_name = (*a)->name.empty() ? SignList::default_name : (*a)->name.c_str();
 
		const std::string &a_name = (*a)->name.empty() ? SignList::default_name : (*a)->name;
 

	
 
		filter.ResetState();
 
		filter.AddLine(a_name);
 
		filter.AddLine(a_name.c_str());
 
		return filter.GetState();
 
	}
 

	
 
	/** Filter sign list excluding OWNER_DEITY */
 
	static bool CDECL OwnerDeityFilter(const Sign * const *a, StringFilter &filter)
 
	{
 
@@ -127,13 +127,13 @@ struct SignList {
 
			this->signs.Filter(&OwnerVisibilityFilter, this->string_filter);
 
		}
 
	}
 
};
 

	
 
bool SignList::match_case = false;
 
char SignList::default_name[64];
 
std::string SignList::default_name;
 

	
 
/** Enum referring to the Hotkeys in the sign list window */
 
enum SignListHotkeys {
 
	SLHK_FOCUS_FILTER_BOX, ///< Focus the edit box for editing the filter string
 
};
 

	
 
@@ -162,13 +162,13 @@ struct SignListWindow : Window, SignList
 
		this->BuildSortSignList();
 
	}
 

	
 
	void OnInit() override
 
	{
 
		/* Default sign name, used if Sign::name is nullptr. */
 
		GetString(SignList::default_name, STR_DEFAULT_SIGN_NAME, lastof(SignList::default_name));
 
		SignList::default_name = GetString(STR_DEFAULT_SIGN_NAME);
 
		this->signs.ForceResort();
 
		this->SortSignsList();
 
		this->SetDirty();
 
	}
 

	
 
	/**
src/station_gui.cpp
Show inline comments
 
@@ -255,13 +255,13 @@ protected:
 
		this->vscroll->SetCount((uint)this->stations.size()); // Update the scrollbar
 
	}
 

	
 
	/** Sort stations by their name */
 
	static bool StationNameSorter(const Station * const &a, const Station * const &b)
 
	{
 
		int r = strnatcmp(a->GetCachedName(), b->GetCachedName()); // Sort by name (natural sorting).
 
		int r = StrNaturalCompare(a->GetCachedName(), b->GetCachedName()); // Sort by name (natural sorting).
 
		if (r == 0) return a->index < b->index;
 
		return r < 0;
 
	}
 

	
 
	/** Sort stations by their type */
 
	static bool StationTypeSorter(const Station * const &a, const Station * const &b)
 
@@ -1183,13 +1183,13 @@ bool CargoSorter::SortStation(StationID 
 
	if (!Station::IsValidID(st1)) {
 
		return Station::IsValidID(st2) ? this->order == SO_ASCENDING : this->SortId(st1, st2);
 
	} else if (!Station::IsValidID(st2)) {
 
		return order == SO_DESCENDING;
 
	}
 

	
 
	int res = strnatcmp(Station::Get(st1)->GetCachedName(), Station::Get(st2)->GetCachedName()); // Sort by name (natural sorting).
 
	int res = StrNaturalCompare(Station::Get(st1)->GetCachedName(), Station::Get(st2)->GetCachedName()); // Sort by name (natural sorting).
 
	if (res == 0) {
 
		return this->SortId(st1, st2);
 
	} else {
 
		return (this->order == SO_ASCENDING) ? res < 0 : res > 0;
 
	}
 
}
src/string.cpp
Show inline comments
 
@@ -33,13 +33,13 @@
 

	
 
#ifdef WITH_UNISCRIBE
 
#	include "os/windows/string_uniscribe.h"
 
#endif
 

	
 
#ifdef WITH_ICU_I18N
 
/* Required by strnatcmp. */
 
/* Required by StrNaturalCompare. */
 
#	include <unicode/ustring.h>
 
#	include "language.h"
 
#	include "gfx_func.h"
 
#endif /* WITH_ICU_I18N */
 

	
 
#if defined(WITH_COCOA)
 
@@ -763,27 +763,27 @@ char *strcasestr(const char *haystack, c
 
 * 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)
 
static std::string_view SkipGarbage(std::string_view str)
 
{
 
	while (*str != '\0' && (*str < '0' || IsInsideMM(*str, ';', '@' + 1) || IsInsideMM(*str, '[', '`' + 1) || IsInsideMM(*str, '{', '~' + 1))) str++;
 
	while (str.size() != 0 && (str[0] < '0' || IsInsideMM(str[0], ';', '@' + 1) || IsInsideMM(str[0], '[', '`' + 1) || IsInsideMM(str[0], '{', '~' + 1))) str.remove_prefix(1);
 
	return str;
 
}
 

	
 
/**
 
 * Compares two strings using case insensitive natural sort.
 
 *
 
 * @param s1 First string to compare.
 
 * @param s2 Second string to compare.
 
 * @param ignore_garbage_at_front Skip punctuation characters in the front
 
 * @return Less than zero if s1 < s2, zero if s1 == s2, greater than zero if s1 > s2.
 
 */
 
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
 
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
 
{
 
	if (ignore_garbage_at_front) {
 
		s1 = SkipGarbage(s1);
 
		s2 = SkipGarbage(s2);
 
	}
 

	
src/string_func.h
Show inline comments
 
@@ -55,12 +55,13 @@ void StrTrimInPlace(std::string &str);
 
[[nodiscard]] bool StrStartsWithIgnoreCase(std::string_view str, const std::string_view prefix);
 
[[nodiscard]] bool StrEndsWith(const std::string_view str, const std::string_view suffix);
 
[[nodiscard]] bool StrEndsWithIgnoreCase(std::string_view str, const std::string_view suffix);
 

	
 
[[nodiscard]] int StrCompareIgnoreCase(const std::string_view str1, const std::string_view str2);
 
[[nodiscard]] bool StrEqualsIgnoreCase(const std::string_view str1, const std::string_view str2);
 
[[nodiscard]] int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front = false);
 

	
 
/**
 
 * Check if a string buffer is empty.
 
 *
 
 * @param s The pointer to the first element of the buffer
 
 * @return true if the buffer starts with the terminating null-character or
 
@@ -274,9 +275,7 @@ static inline bool IsWhitespace(WChar c)
 
#	undef DEFINE_STRCASESTR
 
#else
 
#	define DEFINE_STRCASESTR
 
char *strcasestr(const char *haystack, const char *needle);
 
#endif /* strcasestr is available */
 

	
 
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front = false);
 

	
 
#endif /* STRING_FUNC_H */
src/strings.cpp
Show inline comments
 
@@ -1953,18 +1953,16 @@ const char *GetCurrentLocale(const char 
 
#else
 
const char *GetCurrentLocale(const char *param);
 
#endif /* !(defined(_WIN32) || defined(__APPLE__)) */
 

	
 
bool StringIDSorter(const StringID &a, const StringID &b)
 
{
 
	char stra[512];
 
	char strb[512];
 
	GetString(stra, a, lastof(stra));
 
	GetString(strb, b, lastof(strb));
 
	std::string stra = GetString(a);
 
	std::string strb = GetString(b);
 

	
 
	return strnatcmp(stra, strb) < 0;
 
	return StrNaturalCompare(stra, strb) < 0;
 
}
 

	
 
/**
 
 * Get the language with the given NewGRF language ID.
 
 * @param newgrflangid NewGRF languages ID to check.
 
 * @return The language's metadata, or nullptr if it is not known.
src/town_gui.cpp
Show inline comments
 
@@ -743,13 +743,13 @@ private:
 
		this->SetWidgetDirty(WID_TD_LIST); // Force repaint of the displayed towns.
 
	}
 

	
 
	/** Sort by town name */
 
	static bool TownNameSorter(const Town * const &a, const Town * const &b)
 
	{
 
		return strnatcmp(a->GetCachedName(), b->GetCachedName()) < 0; // Sort by name (natural sorting).
 
		return StrNaturalCompare(a->GetCachedName(), b->GetCachedName()) < 0; // Sort by name (natural sorting).
 
	}
 

	
 
	/** Sort by population (default descending, as big towns are of the most interest). */
 
	static bool TownPopulationSorter(const Town * const &a, const Town * const &b)
 
	{
 
		uint32 a_population = a->cache.population;
src/vehicle_gui.cpp
Show inline comments
 
@@ -1342,13 +1342,13 @@ static bool VehicleNameSorter(const Vehi
 
	if (b != _last_vehicle[1]) {
 
		_last_vehicle[1] = b;
 
		SetDParam(0, b->index);
 
		GetString(last_name[1], STR_VEHICLE_NAME, lastof(last_name[1]));
 
	}
 

	
 
	int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting).
 
	int r = StrNaturalCompare(last_name[0], last_name[1]); // Sort by name (natural sorting).
 
	return (r != 0) ? r < 0: VehicleNumberSorter(a, b);
 
}
 

	
 
/** Sort vehicles by their age */
 
static bool VehicleAgeSorter(const Vehicle * const &a, const Vehicle * const &b)
 
{
src/widgets/dropdown.cpp
Show inline comments
 
@@ -49,16 +49,15 @@ void DropDownListStringItem::Draw(const 
 
 * @param second Right side of comparison.
 
 * @return true if \a first precedes \a second.
 
 * @warning All items in the list need to be derivates of DropDownListStringItem.
 
 */
 
/* static */ bool DropDownListStringItem::NatSortFunc(std::unique_ptr<const DropDownListItem> const &first, std::unique_ptr<const DropDownListItem> const &second)
 
{
 
	char buffer1[512], buffer2[512];
 
	GetString(buffer1, static_cast<const DropDownListStringItem*>(first.get())->String(), lastof(buffer1));
 
	GetString(buffer2, static_cast<const DropDownListStringItem*>(second.get())->String(), lastof(buffer2));
 
	return strnatcmp(buffer1, buffer2) < 0;
 
	std::string str1 = GetString(static_cast<const DropDownListStringItem*>(first.get())->String());
 
	std::string str2 = GetString(static_cast<const DropDownListStringItem*>(second.get())->String());
 
	return StrNaturalCompare(str1, str2) < 0;
 
}
 

	
 
StringID DropDownListParamStringItem::String() const
 
{
 
	for (uint i = 0; i < lengthof(this->decode_params); i++) SetDParam(i, this->decode_params[i]);
 
	return this->string;
0 comments (0 inline, 0 general)