Codechange: replace strnatcmp with C++ string capable version

This commit is contained in:
Rubidium
2023-04-27 15:39:10 +02:00
committed by rubidium42
parent df19673fbd
commit c829930440
22 changed files with 47 additions and 54 deletions

View File

@@ -47,7 +47,7 @@ struct SignList {
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.
@@ -79,10 +79,10 @@ struct SignList {
* 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);
}
@@ -96,10 +96,10 @@ struct SignList {
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();
}
@@ -130,7 +130,7 @@ struct SignList {
};
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 {
@@ -165,7 +165,7 @@ struct SignListWindow : Window, SignList {
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();