-
-
Notifications
You must be signed in to change notification settings - Fork 7k
/
Copy pathStringUtils.java
51 lines (45 loc) · 1.36 KB
/
StringUtils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package processing.app.helpers;
import java.util.List;
public class StringUtils {
public static boolean stringContainsOneOf(String input, List<String> listOfStrings) {
for (String string : listOfStrings) {
if (input.contains(string)) {
return true;
}
}
return false;
}
/**
* Tries to match <b>input</b> with <b>pattern</b>. The pattern can use the
* "*" and "?" globs to match any-char-sequence and any-char respectively.
*
* @param input The string to be checked
* @param pattern The pattern to match
* @return <b>true</b> if the <b>input</b> matches the <b>pattern</b>,
* <b>false</b> otherwise.
*/
public static boolean wildcardMatch(String input, String pattern) {
String regex = pattern.replace("?", ".?").replace("*", ".*?");
return input.matches(regex);
}
/**
* Returns the string without trailing whitespace characters
*
* @param s
* @return
*/
public static String rtrim(String s) {
int i = s.length() - 1;
while (i >= 0 && Character.isWhitespace(s.charAt(i))) {
i--;
}
return s.substring(0, i + 1);
}
public static String join(String[] arr, String separator) {
StringBuffer sb = new StringBuffer();
for (String s : arr) {
sb.append(s).append(separator);
}
return sb.substring(0, sb.length() - separator.length());
}
}