Skip to content

Commit 9b5a87e

Browse files
committed
refine StringUtils.center
1 parent da0f6a8 commit 9b5a87e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/main/java/org/apache/commons/lang3/StringUtils.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,12 @@ public static String center(String str, final int size, final char padChar) {
621621
if (pads <= 0) {
622622
return str;
623623
}
624-
str = leftPad(str, strLen + pads / 2, padChar);
625-
str = rightPad(str, size, padChar);
626-
return str;
624+
if (pads > PAD_LIMIT) {
625+
str = leftPad(str, strLen + pads / 2, String.valueOf(padChar));
626+
str = rightPad(str, size, String.valueOf(padChar));
627+
return str;
628+
}
629+
return repeat(padChar, pads / 2) + str + repeat(padChar, size - (strLen + pads / 2));
627630
}
628631

629632
/**

0 commit comments

Comments
 (0)