aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/util/formatters
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2024-05-12 14:58:27 +0300
committerGravatar Vitaly Takmazov2024-05-12 15:08:24 +0300
commit986cdeb72a6d433b43c990293b8a9d5689e3584b (patch)
treedcdf449747d642b7aa5595c6ac5b8359834263ee /src/main/java/com/juick/util/formatters
parent917744962bfa182345e2c743b2bdce97811e82f9 (diff)
StringUtils.abbreviate
Diffstat (limited to 'src/main/java/com/juick/util/formatters')
-rw-r--r--src/main/java/com/juick/util/formatters/PlainTextFormatter.java27
1 files changed, 2 insertions, 25 deletions
diff --git a/src/main/java/com/juick/util/formatters/PlainTextFormatter.java b/src/main/java/com/juick/util/formatters/PlainTextFormatter.java
index 2e7722e7..682a15b4 100644
--- a/src/main/java/com/juick/util/formatters/PlainTextFormatter.java
+++ b/src/main/java/com/juick/util/formatters/PlainTextFormatter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2020, Juick
+ * Copyright (C) 2008-2024, Juick
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -22,7 +22,6 @@ import com.juick.util.MessageUtils;
import org.apache.commons.lang3.StringUtils;
import org.ocpsoft.prettytime.PrettyTime;
-import java.text.BreakIterator;
import java.util.Date;
import java.util.Locale;
@@ -63,7 +62,7 @@ public class PlainTextFormatter {
sb.append(attachmentUrl).append("\n");
}
if (txt.length() >= cropLength) {
- sb.append(PlainTextFormatter.truncateText(txt, cropLength)).append(" [...]");
+ sb.append(StringUtils.abbreviate(txt, "[…]", cropLength));
} else {
sb.append(txt);
}
@@ -98,26 +97,4 @@ public class PlainTextFormatter {
public static String formatTwitterCard(Message jmsg) {
return MessageUtils.getMessageHashTags(jmsg) + StringUtils.defaultString(jmsg.getText());
}
- /**
- * Truncate text to the nearest word, up to a maximum length specified.
- *
- * @param text
- * @param maxLength
- * @return
- */
- public static String truncateText(String text, int maxLength) {
- if(text != null && text.length() > maxLength) {
- BreakIterator bi = BreakIterator.getWordInstance();
- bi.setText(text);
-
- if(bi.isBoundary(maxLength-1)) {
- return text.substring(0, maxLength-2);
- } else {
- int preceding = bi.preceding(maxLength-1);
- return text.substring(0, preceding-1);
- }
- } else {
- return text;
- }
- }
}