This commit is contained in:
Looly 2022-03-31 22:18:50 +08:00
parent 7baccb4c20
commit 1186a07da5
3 changed files with 30 additions and 13 deletions

View File

@ -781,7 +781,6 @@ public class Convert {
c[i] = '\u3000'; c[i] = '\u3000';
} else if (c[i] < '\177') { } else if (c[i] < '\177') {
c[i] = (char) (c[i] + 65248); c[i] = (char) (c[i] + 65248);
} }
} }
return new String(c); return new String(c);

View File

@ -16,7 +16,7 @@ import java.util.List;
*/ */
public class ConsoleTable { public class ConsoleTable {
private static final char ROW_LINE = '-'; private static final char ROW_LINE = '';
private static final char COLUMN_LINE = '|'; private static final char COLUMN_LINE = '|';
private static final char CORNER = '+'; private static final char CORNER = '+';
private static final char SPACE = '\u3000'; private static final char SPACE = '\u3000';
@ -83,9 +83,9 @@ public class ConsoleTable {
private void fillColumns(List<String> l, String[] columns) { private void fillColumns(List<String> l, String[] columns) {
for (int i = 0; i < columns.length; i++) { for (int i = 0; i < columns.length; i++) {
String column = columns[i]; String column = columns[i];
String col = Convert.toSBC(column); column = Convert.toSBC(column);
l.add(col); l.add(column);
int width = col.length(); int width = column.length();
if (width > columnCharNumber.get(i)) { if (width > columnCharNumber.get(i)) {
columnCharNumber.set(i, width); columnCharNumber.set(i, width);
} }
@ -115,19 +115,19 @@ public class ConsoleTable {
* @param list 表头列表或者表体列表 * @param list 表头列表或者表体列表
*/ */
private void fillRow(StringBuilder sb, List<List<String>> list) { private void fillRow(StringBuilder sb, List<List<String>> list) {
for (List<String> r : list) { for (List<String> row : list) {
for (int i = 0; i < r.size(); i++) { for (int i = 0; i < row.size(); i++) {
if (i == 0) { if (i == 0) {
sb.append(COLUMN_LINE); sb.append(COLUMN_LINE);
} }
String header = r.get(i); String value = row.get(i);
sb.append(SPACE); sb.append(SPACE);
sb.append(header); sb.append(value);
sb.append(SPACE); sb.append(SPACE);
int l = header.length(); int length = value.length();
int lw = columnCharNumber.get(i); int maxLength = columnCharNumber.get(i);
if (lw > l) { if (maxLength > length) {
for (int j = 0; j < (lw - l); j++) { for (int j = 0; j < (maxLength - length); j++) {
sb.append(SPACE); sb.append(SPACE);
} }
} }

View File

@ -4437,4 +4437,22 @@ public class CharSequenceUtil {
public static String normalize(CharSequence str) { public static String normalize(CharSequence str) {
return Normalizer.normalize(str, Normalizer.Form.NFC); return Normalizer.normalize(str, Normalizer.Form.NFC);
} }
/**
* 在给定字符串末尾填充指定字符以达到给定长度<br>
* 如果字符串本身的长度大于等于length返回原字符串
*
* @param str 字符串
* @param fixedChar 补充的字符
* @param length 补充到的长度
* @return 补充后的字符串
* @since 5.8.0
*/
public static String fixLength(CharSequence str, char fixedChar, int length) {
final int fixedLength = length - str.length();
if (fixedLength <= 0) {
return str.toString();
}
return str + repeat(fixedChar, fixedLength);
}
} }