summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorA Thousand Ships <96648715+AThousandShips@users.noreply.github.com>2024-03-24 17:54:20 +0100
committerA Thousand Ships <96648715+AThousandShips@users.noreply.github.com>2024-03-24 17:54:57 +0100
commitbb6305d1c40b8d75e1d58bc57811479d1d2986c9 (patch)
treef6098ec87cfd77b346bd6a64d445f846f7e55ca0
parent99ff024f78f65ba0bc54fb409cfeca43ba2008fe (diff)
downloadredot-engine-bb6305d1c40b8d75e1d58bc57811479d1d2986c9.tar.gz
[Core] Fix incorrect file sort method
-rw-r--r--core/string/ustring.cpp7
-rw-r--r--tests/core/string/test_string.h2
2 files changed, 5 insertions, 4 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index 93a08fd8b5..bdef1b9bbe 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -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) {
// 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 `.`
- if (*r_this_str != '_' && *r_that_str == '_') {
+ if (*r_this_str != '_') {
return *r_this_str == '.' ? -1 : 1;
- }
- if (*r_this_str == '_' && *r_that_str != '_') {
+ } else if (*r_that_str != '_') {
return *r_that_str == '.' ? 1 : -1;
}
r_this_str++;
diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h
index 027dcac92d..64f03e5879 100644
--- a/tests/core/string/test_string.h
+++ b/tests/core/string/test_string.h
@@ -338,10 +338,12 @@ TEST_CASE("[String] Natural compare function test") {
TEST_CASE("[String] File compare function test") {
String a = "_img2.png";
+ String b = "img2.png";
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 after period.");
+ CHECK(b.filenocasecmp_to("img3.png") < 0);
}
TEST_CASE("[String] hex_encode_buffer") {