@@ -14,57 +14,58 @@ public class WwwScanner implements Scanner {
14
14
@ Override
15
15
public LinkSpan scan (final CharSequence input , int triggerIndex , int rewindIndex ) {
16
16
final int afterDot = triggerIndex + 4 ;
17
- if (afterDot >= input .length () || !isWWW (input , triggerIndex )) {
17
+ if (afterDot >= input .length () || !isWww (input , triggerIndex )) {
18
18
return null ;
19
19
}
20
20
21
21
final int first = findFirst (input , triggerIndex , rewindIndex );
22
22
if (first == -1 ) {
23
23
return null ;
24
24
}
25
-
25
+
26
26
int last = findLast (input , afterDot );
27
27
if (last == -1 ) {
28
28
return null ;
29
29
}
30
30
31
31
return new LinkSpanImpl (LinkType .WWW , first , last + 1 );
32
32
}
33
-
33
+
34
34
private static int findFirst (final CharSequence input , final int beginIndex , final int rewindIndex ) {
35
35
if (beginIndex == rewindIndex ) {
36
36
return beginIndex ;
37
37
}
38
-
38
+
39
39
// Is the character before www. allowed?
40
40
if (isAllowed (input .charAt (beginIndex - 1 ))) {
41
41
return beginIndex ;
42
42
}
43
-
43
+
44
44
return -1 ;
45
45
}
46
-
46
+
47
47
private static int findLast (final CharSequence input , final int beginIndex ) {
48
48
final int last = Scanners .findUrlEnd (input , beginIndex );
49
-
49
+
50
50
// Make sure there is at least one dot after the first dot,
51
51
// so www.something is not allowed, but www.something.co.uk is
52
52
int pointer = last ;
53
53
while (--pointer > beginIndex ) {
54
- if (input .charAt (pointer ) == '.' && pointer > beginIndex ) return last ;
54
+ if (input .charAt (pointer ) == '.' && pointer > beginIndex ) {
55
+ return last ;
56
+ }
55
57
}
56
-
58
+
57
59
return -1 ;
58
60
}
59
-
61
+
60
62
private static boolean isAllowed (char c ) {
61
63
return c != '.' && !Scanners .isAlnum (c );
62
64
}
63
-
64
- private static boolean isWWW (final CharSequence input , final int triggerIndex ) {
65
- return
66
- (input .charAt (triggerIndex + 1 ) == 'w' )
67
- && (input .charAt (triggerIndex + 2 ) == 'w' )
68
- && input .charAt (triggerIndex + 3 ) == '.' ;
65
+
66
+ private static boolean isWww (final CharSequence input , final int triggerIndex ) {
67
+ return input .charAt (triggerIndex + 1 ) == 'w'
68
+ && input .charAt (triggerIndex + 2 ) == 'w'
69
+ && input .charAt (triggerIndex + 3 ) == '.' ;
69
70
}
70
71
}
0 commit comments