summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMewPurPur <mew.pur.pur@abv.bg>2023-07-08 15:54:05 +0300
committerMewPurPur <mew.pur.pur@abv.bg>2023-07-08 16:16:01 +0300
commitcc5500f7de954e461c843237346527220bbce0ba (patch)
treeba55ea648f53f482e1439b7b762acd5398727fa1
parent443820686cad24bbdd7e7050fa3d3f33f43a7bb5 (diff)
downloadredot-engine-cc5500f7de954e461c843237346527220bbce0ba.tar.gz
Fix erroneous pad_zeros warning
-rw-r--r--core/string/ustring.cpp9
-rw-r--r--tests/core/string/test_string.h2
2 files changed, 7 insertions, 4 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index 49c7ead423..12e6423724 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -4281,12 +4281,13 @@ String String::pad_zeros(int p_digits) const {
begin++;
}
- if (begin >= end) {
+ int zeros_to_add = p_digits - (end - begin);
+
+ if (zeros_to_add <= 0) {
return s;
+ } else {
+ return s.insert(begin, String("0").repeat(zeros_to_add));
}
-
- int zeros_to_add = p_digits - (end - begin);
- return s.insert(begin, String("0").repeat(zeros_to_add));
}
String String::trim_prefix(const String &p_prefix) const {
diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h
index 5a2f871430..93b237788d 100644
--- a/tests/core/string/test_string.h
+++ b/tests/core/string/test_string.h
@@ -1095,7 +1095,9 @@ TEST_CASE("[String] pad") {
s = String("10.10");
CHECK(s.pad_decimals(4) == U"10.1000");
+ CHECK(s.pad_decimals(1) == U"10.1");
CHECK(s.pad_zeros(4) == U"0010.10");
+ CHECK(s.pad_zeros(1) == U"10.10");
}
TEST_CASE("[String] is_subsequence_of") {