remove trailing ) in urls

This commit is contained in:
Daniel Gultsch 2018-03-14 21:59:18 +01:00
parent 3c932e9fa6
commit fe90e70bb1
1 changed files with 28 additions and 22 deletions

View File

@ -98,33 +98,39 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
+ "\\;\\/\\?\\@\\&\\=\\#\\~\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])" + "\\;\\/\\?\\@\\&\\=\\#\\~\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])"
+ "|(?:\\%[a-fA-F0-9]{2}))+"); + "|(?:\\%[a-fA-F0-9]{2}))+");
private static final Linkify.TransformFilter WEBURL_TRANSFORM_FILTER = new Linkify.TransformFilter() { private static final Linkify.TransformFilter WEBURL_TRANSFORM_FILTER = (matcher, url) -> {
@Override
public String transformUrl(Matcher matcher, String url) {
if (url == null) { if (url == null) {
return null; return null;
} }
final String lcUrl = url.toLowerCase(Locale.US); final String lcUrl = url.toLowerCase(Locale.US);
if (lcUrl.startsWith("http://") || lcUrl.startsWith("https://")) { if (lcUrl.startsWith("http://") || lcUrl.startsWith("https://")) {
return url; return removeTrailingBracket(url);
} else { } else {
return "http://" + url; return "http://" + removeTrailingBracket(url);
}
}
};
private static final Linkify.MatchFilter WEBURL_MATCH_FILTER = new Linkify.MatchFilter() {
@Override
public boolean acceptMatch(CharSequence cs, int start, int end) {
return start < 1 || (cs.charAt(start - 1) != '@' && cs.charAt(start - 1) != '.' && !cs.subSequence(Math.max(0, start - 3), start).equals("://"));
} }
}; };
private static final Linkify.MatchFilter XMPPURI_MATCH_FILTER = new Linkify.MatchFilter() { private static String removeTrailingBracket(final String url) {
@Override int numOpenBrackets = 0;
public boolean acceptMatch(CharSequence s, int start, int end) { for(char c : url.toCharArray()) {
if (c=='(') {
++numOpenBrackets;
} else if (c==')') {
--numOpenBrackets;
}
}
if (numOpenBrackets != 0 && url.charAt(url.length() - 1) == ')') {
return url.substring(0,url.length() - 1);
} else {
return url;
}
}
private static final Linkify.MatchFilter WEBURL_MATCH_FILTER = (cs, start, end) -> start < 1 || (cs.charAt(start - 1) != '@' && cs.charAt(start - 1) != '.' && !cs.subSequence(Math.max(0, start - 3), start).equals("://"));
private static final Linkify.MatchFilter XMPPURI_MATCH_FILTER = (s, start, end) -> {
XmppUri uri = new XmppUri(s.subSequence(start, end).toString()); XmppUri uri = new XmppUri(s.subSequence(start, end).toString());
return uri.isJidValid(); return uri.isJidValid();
}
}; };
private final XmppActivity activity; private final XmppActivity activity;