Merge branch 'trailing_url_slash' of https://github.com/klonfish/Conversations into klonfish-trailing_url_slash

This commit is contained in:
Daniel Gultsch 2018-06-11 16:19:51 +02:00
commit 17db77ed5d
2 changed files with 36 additions and 18 deletions

View file

@ -104,7 +104,42 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
return "http://" + removeTrailingBracket(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 String removeTrailingBracket(final String url) {
int numOpenBrackets = 0;
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) -> {
if (start > 0) {
if (cs.charAt(start - 1) == '@' || cs.charAt(start - 1) == '.'
|| cs.subSequence(Math.max(0, start - 3), start).equals("://")) {
return false;
}
}
if (end < cs.length()) {
// Reject strings that were probably matched only because they contain a dot followed by
// by some known TLD (see also comment for WORD_BOUNDARY in Patterns.java)
if (Character.isAlphabetic(cs.charAt(end-1)) && Character.isAlphabetic(cs.charAt(end))) {
return false;
}
}
return true;
};
private static final Linkify.MatchFilter XMPPURI_MATCH_FILTER = (s, start, end) -> {
XmppUri uri = new XmppUri(s.subSequence(start, end).toString());
return uri.isJidValid();
@ -127,21 +162,6 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
updatePreferences();
}
private static String removeTrailingBracket(final String url) {
int numOpenBrackets = 0;
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;
}
}
public static boolean cancelPotentialWork(Message message, ImageView imageView) {
final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView);

View file

@ -353,7 +353,6 @@ public class Patterns {
+ "(?:" + PORT_NUMBER + ")?"
+ ")"
+ "(?:" + PATH_AND_QUERY + ")?"
+ WORD_BOUNDARY
+ ")";
/**
* Regular expression to match strings that start with a supported protocol. Rules for domain
@ -367,7 +366,6 @@ public class Patterns {
+ "(?:" + PORT_NUMBER + ")?"
+ ")"
+ "(?:" + PATH_AND_QUERY + ")?"
+ WORD_BOUNDARY
+ ")";
/**
* Regular expression pattern to match IRIs. If a string starts with http(s):// the expression