From 3ac29727fb53c0a8adc20e003115f4dd9ab48907 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 9 Nov 2013 01:02:47 +0100 Subject: [PATCH] Extract function to detect whether a freenet link matches the posting Sone. --- src/main/java/net/pterodactylus/sone/text/SoneTextParser.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java index 78d9bdc..d41a7e2 100644 --- a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java +++ b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java @@ -259,7 +259,7 @@ public class SoneTextParser implements Parser { if (name == null) { name = link.substring(0, Math.min(9, link.length())); } - boolean fromPostingSone = ((linkType == LinkType.SSK) || (linkType == LinkType.USK)) && (context != null) && (context.getPostingSone() != null) && link.substring(4, Math.min(link.length(), 47)).equals(context.getPostingSone().getId()); + boolean fromPostingSone = ((linkType == LinkType.SSK) || (linkType == LinkType.USK)) && linkMatchesPostingSone(context, link); parts.add(new FreenetLinkPart(link, name, fromPostingSone)); } catch (MalformedURLException mue1) { /* not a valid link, insert as plain text. */ @@ -312,6 +312,10 @@ public class SoneTextParser implements Parser { } } + private boolean linkMatchesPostingSone(SoneTextParserContext context, String link) { + return (context != null) && (context.getPostingSone() != null) && link.substring(4, Math.min(link.length(), 47)).equals(context.getPostingSone().getId()); + } + private int findNextWhitespace(String line) { Matcher matcher = whitespacePattern.matcher(line); return matcher.find(0) ? matcher.start() : line.length(); -- 2.7.4