Pads the given string with leading spaces to reach the specified maximum length. @param str the string to pad @param maxChars the target length @return the padded string
(String str, int maxChars)
| 85 | * @return the padded string |
| 86 | */ |
| 87 | public String padLeft(String str, int maxChars) { |
| 88 | String result = str; |
| 89 | int charsToAdd = maxChars - str.length(); |
| 90 | if (charsToAdd > 0) { |
| 91 | result = " ".repeat(charsToAdd) + str; |
| 92 | } |
| 93 | return result; |
| 94 | } |
| 95 | |
| 96 | |
| 97 | // We try to mimic httpd here, as we do everywhere. |