Skip to content

Commit

Permalink
Merge pull request #79202 from MewPurPur/fix-pad-zeros-error
Browse files Browse the repository at this point in the history
Fix erroneous `pad_zeros()` warning
  • Loading branch information
akien-mga committed Jul 8, 2023
2 parents 8eeb7c9 + cc5500f commit 83cc5d4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 5 additions & 4 deletions core/string/ustring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions tests/core/string/test_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit 83cc5d4

Please sign in to comment.