forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrestoConstantUtils.java
More file actions
40 lines (31 loc) · 1.25 KB
/
PrestoConstantUtils.java
File metadata and controls
40 lines (31 loc) · 1.25 KB
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
package sqlancer.presto;
import java.math.BigDecimal;
import java.math.RoundingMode;
public final class PrestoConstantUtils {
private PrestoConstantUtils() {
}
public static String removeNoneAscii(String str) {
return str.replaceAll("[^\\x00-\\x7F]", "");
}
public static String removeNonePrintable(String str) { // All Control Char
return str.replaceAll("[\\p{C}]", "");
}
public static String removeOthersControlChar(String str) { // Some Control Char
return str.replaceAll("[\\p{Cntrl}\\p{Cc}\\p{Cf}\\p{Co}\\p{Cn}]", "");
}
public static String removeAllControlChars(String str) {
return removeOthersControlChar(removeNonePrintable(str)).replaceAll("[\\r\\n\\t]", "");
}
public static BigDecimal getDecimal(double val, int scale, int precision) {
int part = precision - scale;
// long part
long lng = (long) val;
// decimal places
double d1 = val - lng;
String xStr = Long.toString(lng);
String substring = xStr.substring(xStr.length() - part);
long newX = substring.isEmpty() ? 0 : Long.parseLong(substring);
double finalD = newX + d1;
return new BigDecimal(finalD).setScale(scale, RoundingMode.CEILING);
}
}