-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringUtils.java
35 lines (27 loc) · 979 Bytes
/
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
package com.osotnikov.string;
public class StringUtils {
public static boolean equalsIgnoreWhitespace(String left, String right) {
if(left == right) {
return true;
} else if(left == null || right == null) {
return false;
} else {
left = left.replaceAll("\\s+","");
right = right.replaceAll("\\s+","");
return left.equals(right);
}
}
public static boolean equalsIgnoreWhitespaceApartFromNewlinesButTrim(String left, String right) {
if(left == right) {
return true;
} else if(left == null || right == null) {
return false;
} else {
left = left.replaceAll("\\r\\n","\n").trim();
right = right.replaceAll("\\r\\n","\n").trim();
left = left.replaceAll("[^\\S\\r\\n]+","");
right = right.replaceAll("[^\\S\\r\\n]+","");
return left.equals(right);
}
}
}