Fix erroneous pad_zeros warning

(cherry picked from commit cc5500f7de)
This commit is contained in:
MewPurPur 2023-07-08 15:54:05 +03:00 committed by Yuri Sizov
parent fb8e21bd6d
commit a4547db15b
2 changed files with 8 additions and 5 deletions

View File

@ -4281,12 +4281,13 @@ String String::pad_zeros(int p_digits) const {
begin++; begin++;
} }
if (begin >= end) {
return s;
}
int zeros_to_add = p_digits - (end - begin); int zeros_to_add = p_digits - (end - begin);
return s.insert(begin, String("0").repeat(zeros_to_add));
if (zeros_to_add <= 0) {
return s;
} else {
return s.insert(begin, String("0").repeat(zeros_to_add));
}
} }
String String::trim_prefix(const String &p_prefix) const { String String::trim_prefix(const String &p_prefix) const {

View File

@ -1095,7 +1095,9 @@ TEST_CASE("[String] pad") {
s = String("10.10"); s = String("10.10");
CHECK(s.pad_decimals(4) == U"10.1000"); 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(4) == U"0010.10");
CHECK(s.pad_zeros(1) == U"10.10");
} }
TEST_CASE("[String] is_subsequence_of") { TEST_CASE("[String] is_subsequence_of") {