From 358b2cc71703c3cb12355f9a109e0b484ed8c1ba Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 17 Sep 2012 07:04:11 +0200 Subject: [PATCH] Abbreviate excerpts on the last space. --- src/main/java/net/pterodactylus/sone/template/ParserFilter.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java index 1936656..75eff8b 100644 --- a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java +++ b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java @@ -249,7 +249,13 @@ public class ParserFilter implements Filter { for (Part part : parts) { excerpt.append(part.getText()); if (excerpt.length() > 20) { - excerpt.setLength(20); + int lastSpace = excerpt.lastIndexOf(" ", 20); + if (lastSpace > -1) { + excerpt.setLength(lastSpace); + } else { + excerpt.setLength(20); + } + excerpt.append("…"); break; } } -- 2.7.4