X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneTextParser.java;h=81ac75150a7d31656b7344566e3fd5eddd754380;hp=74dcb87172e2b23cebe3252e9b2f5e748f8b9b94;hb=7b55e0be6a3283e43a9bbab98f82aebdd948eb33;hpb=8d06eafb25514dc1371de140acdfd1ae899e0146 diff --git a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java index 74dcb87..81ac751 100644 --- a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java +++ b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java @@ -300,19 +300,12 @@ public class SoneTextParser implements Parser { private int findEndOfLink(String line) { Matcher matcher = whitespacePattern.matcher(line); - if (!matcher.find(0)) { - return line.length(); - } - int nextWhitespace = matcher.start(); - int lastPunctuation = nextWhitespace; - while (isPunctuation(line.charAt(lastPunctuation - 1))) { - lastPunctuation -= 1; - } - if (lastPunctuation < nextWhitespace) { - return lastPunctuation; + int endOfLink = matcher.find() ? matcher.start() : line.length(); + while ((endOfLink > 0) && isPunctuation(line.charAt(endOfLink - 1))) { + endOfLink--; } int openParens = 0; - for (int i = 0; i < nextWhitespace; i++) { + for (int i = 0; i < endOfLink; i++) { switch (line.charAt(i)) { case '(': openParens++; @@ -325,10 +318,10 @@ public class SoneTextParser implements Parser { default: } } - return nextWhitespace; + return endOfLink; } - private boolean isPunctuation(char character) { + private static boolean isPunctuation(char character) { return (character == '.') || (character == ','); }