- 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--;