2017-05-16 18:40:12 +10:00
|
|
|
package com.keylesspalace.tusky.util;
|
|
|
|
|
2017-05-18 00:06:37 +10:00
|
|
|
import android.util.Patterns;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2017-05-16 18:40:12 +10:00
|
|
|
import java.util.Random;
|
2017-05-18 00:06:37 +10:00
|
|
|
import java.util.regex.Matcher;
|
2017-05-16 18:40:12 +10:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2017-05-18 00:06:37 +10:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2017-05-16 18:40:12 +10:00
|
|
|
}
|