chinwag-android/app/src/main/java/com/keylesspalace/tusky/util/StringUtils.java
torrentcome 7cc06d3ad0 (bug fixing) When we share by an app : the text shared is not just an URL but a small text with the URL inside.
So we parse the text until find an url.
Take the first one and send it to the parse
2017-05-17 16:06:37 +02:00

34 lines
1,012 B
Java

package com.keylesspalace.tusky.util;
import android.util.Patterns;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.regex.Matcher;
public class StringUtils {
public final static String carriageReturn = System.getProperty("line.separator");
final static String QUOTE = "\"";
public static String randomAlphanumericString(int count) {
char[] chars = new char[count];
Random random = new Random();
final String POSSIBLE_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (int i = 0; i < count; i++) {
chars[i] = POSSIBLE_CHARS.charAt(random.nextInt(POSSIBLE_CHARS.length()));
}
return new String(chars);
}
static List<String> extractUrl(String text) {
List<String> links = new ArrayList<>();
Matcher m = Patterns.WEB_URL.matcher(text);
while (m.find()) {
String url = m.group();
links.add(url);
}
return links;
}
}