fix #1054: Avoid incorrect UI layout caused by long strings

This commit is contained in:
Glavo
2021-09-22 13:27:07 +08:00
committed by Yuhui Huang
parent cbe9f7474e
commit bcaf3de164
2 changed files with 23 additions and 6 deletions

View File

@@ -21,10 +21,7 @@ import org.jackhuang.hmcl.util.platform.OperatingSystem;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.*;
import java.util.regex.Pattern;
/**
@@ -245,6 +242,17 @@ public final class StringUtils {
return result.toString();
}
public static int MAX_SHORT_STRING_LENGTH = 77;
public static Optional<String> truncate(String str) {
if (str.length() <= MAX_SHORT_STRING_LENGTH) {
return Optional.empty();
}
final int halfLength = (MAX_SHORT_STRING_LENGTH - 5) / 2;
return Optional.of(str.substring(0, halfLength) + " ... " + str.substring(str.length() - halfLength));
}
/**
* Class for computing the longest common subsequence between strings.
*/