diff --git a/src/main/java/org/nibor/autolink/internal/WwwScanner.java b/src/main/java/org/nibor/autolink/internal/WwwScanner.java index 0bc78b7..e90153a 100644 --- a/src/main/java/org/nibor/autolink/internal/WwwScanner.java +++ b/src/main/java/org/nibor/autolink/internal/WwwScanner.java @@ -14,7 +14,7 @@ public class WwwScanner implements Scanner { @Override public LinkSpan scan(final CharSequence input, int triggerIndex, int rewindIndex) { final int afterDot = triggerIndex + 4; - if (afterDot >= input.length() || !isWWW(input, triggerIndex)) { + if (afterDot >= input.length() || !isWww(input, triggerIndex)) { return null; } @@ -22,7 +22,7 @@ public LinkSpan scan(final CharSequence input, int triggerIndex, int rewindIndex if (first == -1) { return null; } - + int last = findLast(input, afterDot); if (last == -1) { return null; @@ -30,41 +30,42 @@ public LinkSpan scan(final CharSequence input, int triggerIndex, int rewindIndex return new LinkSpanImpl(LinkType.WWW, first, last + 1); } - + private static int findFirst(final CharSequence input, final int beginIndex, final int rewindIndex) { if (beginIndex == rewindIndex) { return beginIndex; } - + // Is the character before www. allowed? if (isAllowed(input.charAt(beginIndex - 1))) { return beginIndex; } - + return -1; } - + private static int findLast(final CharSequence input, final int beginIndex) { final int last = Scanners.findUrlEnd(input, beginIndex); - + // Make sure there is at least one dot after the first dot, // so www.something is not allowed, but www.something.co.uk is int pointer = last; while (--pointer > beginIndex) { - if (input.charAt(pointer) == '.' && pointer > beginIndex) return last; + if (input.charAt(pointer) == '.' && pointer > beginIndex) { + return last; + } } - + return -1; } - + private static boolean isAllowed(char c) { return c != '.' && !Scanners.isAlnum(c); } - - private static boolean isWWW(final CharSequence input, final int triggerIndex) { - return - (input.charAt(triggerIndex + 1) == 'w') - && (input.charAt(triggerIndex + 2) == 'w') - && input.charAt(triggerIndex + 3) == '.'; + + private static boolean isWww(final CharSequence input, final int triggerIndex) { + return input.charAt(triggerIndex + 1) == 'w' + && input.charAt(triggerIndex + 2) == 'w' + && input.charAt(triggerIndex + 3) == '.'; } }