Skip to content

Commit

Permalink
refine StringUtils.center
Browse files Browse the repository at this point in the history
  • Loading branch information
XenoAmess committed Jun 29, 2020
1 parent da0f6a8 commit 9b5a87e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/main/java/org/apache/commons/lang3/StringUtils.java
Expand Up @@ -621,9 +621,12 @@ public static String center(String str, final int size, final char padChar) {
if (pads <= 0) {
return str;
}
str = leftPad(str, strLen + pads / 2, padChar);
str = rightPad(str, size, padChar);
return str;
if (pads > PAD_LIMIT) {
str = leftPad(str, strLen + pads / 2, String.valueOf(padChar));
str = rightPad(str, size, String.valueOf(padChar));
return str;
}
return repeat(padChar, pads / 2) + str + repeat(padChar, size - (strLen + pads / 2));
}

/**
Expand Down

0 comments on commit 9b5a87e

Please sign in to comment.