Fix natural sorting order in EditorFileDialog, FileDialog and EditorFileSystemDirectory
Make EditorFileDialog, FileDialog and EditorFileSystemDirectory alphanumerical sorting more natural Added a new method 'naturalnocasecmp_to' and comparator 'NaturalNoCaseComparator' to String. Fixes #8712.
This commit is contained in:
parent
ed6baffc72
commit
f2564ca97f
5 changed files with 67 additions and 9 deletions
|
|
@ -53,6 +53,8 @@
|
|||
#define MAX_DIGITS 6
|
||||
#define UPPERCASE(m_c) (((m_c) >= 'a' && (m_c) <= 'z') ? ((m_c) - ('a' - 'A')) : (m_c))
|
||||
#define LOWERCASE(m_c) (((m_c) >= 'A' && (m_c) <= 'Z') ? ((m_c) + ('a' - 'A')) : (m_c))
|
||||
#define IS_DIGIT(m_d) ((m_d) >= '0' && (m_d) <= '9')
|
||||
#define IS_HEX_DIGIT(m_d) (((m_d) >= '0' && (m_d) <= '9') || ((m_d) >= 'a' && (m_d) <= 'f') || ((m_d) >= 'A' && (m_d) <= 'F'))
|
||||
|
||||
/** STRING **/
|
||||
|
||||
|
|
@ -481,6 +483,56 @@ signed char String::casecmp_to(const String &p_str) const {
|
|||
return 0; //should never reach anyway
|
||||
}
|
||||
|
||||
signed char String::naturalnocasecmp_to(const String &p_str) const {
|
||||
|
||||
const CharType *this_str = c_str();
|
||||
const CharType *that_str = p_str.c_str();
|
||||
|
||||
if (this_str && that_str) {
|
||||
while (*this_str) {
|
||||
|
||||
if (!*that_str)
|
||||
return 1;
|
||||
else if (IS_DIGIT(*this_str)) {
|
||||
|
||||
int64_t this_int, that_int;
|
||||
|
||||
if (!IS_DIGIT(*that_str))
|
||||
return -1;
|
||||
|
||||
/* Compare the numbers */
|
||||
this_int = to_int(this_str);
|
||||
that_int = to_int(that_str);
|
||||
|
||||
if (this_int < that_int)
|
||||
return -1;
|
||||
else if (this_int > that_int)
|
||||
return 1;
|
||||
|
||||
/* Skip */
|
||||
while (IS_DIGIT(*this_str))
|
||||
this_str++;
|
||||
while (IS_DIGIT(*that_str))
|
||||
that_str++;
|
||||
} else if (IS_DIGIT(*that_str))
|
||||
return 1;
|
||||
else {
|
||||
if (_find_upper(*this_str) < _find_upper(*that_str)) //more than
|
||||
return -1;
|
||||
else if (_find_upper(*this_str) > _find_upper(*that_str)) //less than
|
||||
return 1;
|
||||
|
||||
this_str++;
|
||||
that_str++;
|
||||
}
|
||||
}
|
||||
if (*that_str)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void String::erase(int p_pos, int p_chars) {
|
||||
|
||||
*this = left(p_pos) + substr(p_pos + p_chars, length() - ((p_pos + p_chars)));
|
||||
|
|
@ -1698,9 +1750,6 @@ bool String::is_numeric() const {
|
|||
return true; // TODO: Use the parser below for this instead
|
||||
};
|
||||
|
||||
#define IS_DIGIT(m_d) ((m_d) >= '0' && (m_d) <= '9')
|
||||
#define IS_HEX_DIGIT(m_d) (((m_d) >= '0' && (m_d) <= '9') || ((m_d) >= 'a' && (m_d) <= 'f') || ((m_d) >= 'A' && (m_d) <= 'F'))
|
||||
|
||||
template <class C>
|
||||
static double built_in_strtod(const C *string, /* A decimal ASCII floating-point number,
|
||||
* optionally preceded by white space. Must
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue