Util: New util to truncate a string that won't split across a surrogate pair

This commit is contained in:
zzz
2018-01-10 17:39:58 +00:00
parent 50eb93deec
commit 541dae36d4
4 changed files with 25 additions and 4 deletions

View File

@@ -1534,7 +1534,7 @@ public class I2PSnarkServlet extends BasicServlet {
String basename = snark.getBaseName();
String fullBasename = basename;
if (basename.length() > MAX_DISPLAYED_FILENAME_LENGTH) {
String start = basename.substring(0, MAX_DISPLAYED_FILENAME_LENGTH);
String start = ServletUtil.truncate(basename, MAX_DISPLAYED_FILENAME_LENGTH);
if (start.indexOf(' ') < 0 && start.indexOf('-') < 0) {
// browser has nowhere to break it
basename = start + HELLIP;