1 | if (ignoreLinks) {↵ | | 1 | if (ignoreLinks) {↵
|
2 | // Do not take existing link tags into account↵ | | 2 | // Do not take existing link tags into account↵
|
3 | return substituteEmailAddress(s);↵ | | 3 | return substituteURL(s);↵
|
4 | }↵ | | 4 | }↵
|
|
5 | // initialisation↵ | | 5 | // initialisation↵
|
6 | Matcher noLinkMatcher = EMAIL_PATTERN.matcher(s);↵ | | 6 | Matcher noLinkMatcher = URL_PATTERN.matcher(s);↵
|
7 | Matcher withLinkMatcher = EMAIL_PATTERN_INC_LINK.matcher(s);↵ | | 7 | Matcher withLinkMatcher = URL_PATTERN_INC_LINK.matcher(s);↵
|
8 | int pos = 0; // current position in s↵ | | 8 | int pos = 0; // current position in s↵
|
9 | int length = s.length();↵ | | 9 | int length = s.length();↵
|
10 | StringBuffer buf = new StringBuffer();↵ | | 10 | StringBuffer buf = new StringBuffer();↵
|
|
11 | while (pos < length) {↵ | | 11 | while (pos < length) {↵
|
12 | if (noLinkMatcher.find(pos)) {↵ | | 12 | if (noLinkMatcher.find(pos)) {↵
|
13 | // an email adress was found - check whether its already a link↵ | | 13 | // an url - check whether its already a link↵
|
14 | int s1 = noLinkMatcher.start();↵ | | 14 | int s1 = noLinkMatcher.start();↵
|
15 | int e1 = noLinkMatcher.end();↵ | | 15 | int e1 = noLinkMatcher.end();↵
|
16 | boolean insertLink;↵ | | 16 | boolean insertLink;↵
|
|
17 | if (withLinkMatcher.find(pos)) {↵ | | 17 | if (withLinkMatcher.find(pos)) {↵
|
18 | // found an email address with links - is it the same?↵ | | 18 | // found an url with links - is it the same?↵
|
19 | int s2 = withLinkMatcher.start();↵ | | 19 | int s2 = withLinkMatcher.start();↵
|
20 | int e2 = withLinkMatcher.end();↵ | | 20 | int e2 = withLinkMatcher.end();↵
|
21 | ↵ | | |
|
22 | if ((s2 < s1) && (e2 > e1)) {↵ | | 21 | if ((s2 < s1) && (e2 > e1)) {↵
|
23 | // same email adress - just append and continue↵ | | 22 | // same url - just append and continue↵
|
24 | buf.append(s.substring(pos, e2));↵ | | 23 | buf.append(s.substring(pos, e2));↵
|
25 | pos = e2;↵ | | 24 | pos = e2;↵
|
26 | insertLink = false; // already handled↵ | | 25 | insertLink = false; // already handled↵
|
27 | } else {↵ | | 26 | } else {↵
|
28 | // not the same↵ | | 27 | // not the same↵
|
29 | insertLink = true;↵ | | 28 | insertLink = true;↵
|
30 | } | | 29 | }
|