summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/parserutils/DoubleMatcher.java
blob: 7480020f3d1d36240eb31092df5fd2c98cf37ff4 (plain)
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 bjc.utils.parserutils;

import static bjc.utils.misc.PropertyDB.applyFormat;
import static bjc.utils.misc.PropertyDB.getRegex;

import java.util.regex.Pattern;

/*
 * Checks if a string would pass Double.parseDouble.
 *
 * Uses a regex from the javadoc for Double.valueOf()
 */
class DoubleMatcher {
	/*
	 * Unit pieces.
	 */
	private static final String rDecDigits = getRegex("fpDigits");
	private static final String rHexDigits = getRegex("fpHexDigits");
	private static final String rExponent
			= applyFormat("fpExponent", getRegex("fpExponent"), rDecDigits);

	/*
	 * Decimal floating point numbers.
	 */
	private static final String rSimpleDec
			= applyFormat("fpDecimalDecimal", rDecDigits, rExponent);
	private static final String rSimpleIntDec
			= applyFormat("fpDecimalInteger", rDecDigits, rExponent);

	/*
	 * Hex floating point numbers.
	 */
	private static final String rHexInt = applyFormat("fpHexInteger", rHexDigits);
	private static final String rHexDec = applyFormat("fpHexDecimal", rHexDigits);
	private static final String rHexLead = applyFormat("fpHexLeader", rHexInt, rHexDec);
	private static final String rHexString
			= applyFormat("fpHexString", rHexLead, rDecDigits);

	/*
	 * Floating point components.
	 */
	private static final String rFPLeader = getRegex("fpLeader");
	private static final String rFPNum
			= applyFormat("fpNumber", rSimpleIntDec, rSimpleDec, rHexString);

	/*
	 * Full double.
	 */
	public static final String rawDouble = applyFormat("fpDouble", rFPLeader, rFPNum);
	public static final Pattern doubleLiteral = Pattern.compile("\\A" + rawDouble + "\\Z");
}