From 541f49177de5f63a97d94fe74ffb60badbf5d4c9 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:04:42 +0100 Subject: [PATCH] Extract functions to detect long-enough links. --- .../java/net/pterodactylus/sone/text/SoneTextParser.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java index d41a7e2..efb36c4 100644 --- a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java +++ b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java @@ -207,7 +207,7 @@ public class SoneTextParser implements Parser { } if (linkType == LinkType.SONE) { - if (line.length() >= (7 + 43)) { + if (lineIsLongEnoughToContainASoneLink(line)) { String soneId = line.substring(7, 50); Optional sone = database.getSone(soneId); if (!sone.isPresent()) { @@ -226,7 +226,7 @@ public class SoneTextParser implements Parser { continue; } if (linkType == LinkType.POST) { - if (line.length() >= (7 + 36)) { + if (lineIsLongEnoughToContainAPostLink(line)) { String postId = line.substring(7, 43); Optional post = database.getPost(postId); if (post.isPresent()) { @@ -316,6 +316,14 @@ public class SoneTextParser implements Parser { return (context != null) && (context.getPostingSone() != null) && link.substring(4, Math.min(link.length(), 47)).equals(context.getPostingSone().getId()); } + private boolean lineIsLongEnoughToContainAPostLink(String line) { + return line.length() >= (7 + 36); + } + + private boolean lineIsLongEnoughToContainASoneLink(String line) { + return line.length() >= (7 + 43); + } + private int findNextWhitespace(String line) { Matcher matcher = whitespacePattern.matcher(line); return matcher.find(0) ? matcher.start() : line.length(); -- 2.7.4