mirror of
https://github.com/godotengine/godot.git
synced 2024-11-27 09:16:35 +08:00
[Core] Fix incorrect file sort method
This commit is contained in:
parent
99ff024f78
commit
bb6305d1c4
@ -1043,12 +1043,11 @@ signed char String::naturalnocasecmp_to(const String &p_str) const {
|
|||||||
|
|
||||||
static _FORCE_INLINE_ signed char file_cmp_common(const char32_t *&r_this_str, const char32_t *&r_that_str) {
|
static _FORCE_INLINE_ signed char file_cmp_common(const char32_t *&r_this_str, const char32_t *&r_that_str) {
|
||||||
// Compare leading `_` sequences.
|
// Compare leading `_` sequences.
|
||||||
while (*r_this_str && *r_that_str) {
|
while ((*r_this_str == '_' && *r_that_str) || (*r_this_str && *r_that_str == '_')) {
|
||||||
// Sort `_` lower than everything except `.`
|
// Sort `_` lower than everything except `.`
|
||||||
if (*r_this_str != '_' && *r_that_str == '_') {
|
if (*r_this_str != '_') {
|
||||||
return *r_this_str == '.' ? -1 : 1;
|
return *r_this_str == '.' ? -1 : 1;
|
||||||
}
|
} else if (*r_that_str != '_') {
|
||||||
if (*r_this_str == '_' && *r_that_str != '_') {
|
|
||||||
return *r_that_str == '.' ? 1 : -1;
|
return *r_that_str == '.' ? 1 : -1;
|
||||||
}
|
}
|
||||||
r_this_str++;
|
r_this_str++;
|
||||||
|
@ -338,10 +338,12 @@ TEST_CASE("[String] Natural compare function test") {
|
|||||||
|
|
||||||
TEST_CASE("[String] File compare function test") {
|
TEST_CASE("[String] File compare function test") {
|
||||||
String a = "_img2.png";
|
String a = "_img2.png";
|
||||||
|
String b = "img2.png";
|
||||||
|
|
||||||
CHECK(a.nocasecmp_to("img10.png") > 0);
|
CHECK(a.nocasecmp_to("img10.png") > 0);
|
||||||
CHECK_MESSAGE(a.filenocasecmp_to("img10.png") < 0, "Should sort before letters.");
|
CHECK_MESSAGE(a.filenocasecmp_to("img10.png") < 0, "Should sort before letters.");
|
||||||
CHECK_MESSAGE(a.filenocasecmp_to(".img10.png") > 0, "Should sort after period.");
|
CHECK_MESSAGE(a.filenocasecmp_to(".img10.png") > 0, "Should sort after period.");
|
||||||
|
CHECK(b.filenocasecmp_to("img3.png") < 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("[String] hex_encode_buffer") {
|
TEST_CASE("[String] hex_encode_buffer") {
|
||||||
|
Loading…
Reference in New Issue
Block a user