summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/parserutils/DoubleMatcher.java
blob: 83d2d2acc5acf11e7a2879568a8f2572fc245380 (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
package bjc.utils.parserutils;

import java.util.regex.Pattern;

import static bjc.utils.PropertyDB.*;

/*
 * 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	DecDigits	= getRegex("fpDigits");
	private static final String	HexDigits	= getRegex("fpHexDigits");
	private static final String	Exponent	= applyFormat("fpExponent", getRegex("fpExponent"), DecDigits);

	/*
	 * Decimal floating point numbers.
	 */
	private static final String	SIMPLE_DEC	= applyFormat("fpDecimalDecimal", DecDigits, Exponent);
	private static final String	SIMPLE_INTDEC	= applyFormat("fpDecimalInteger", DecDigits, Exponent);

	/*
	 * Hex floating point numbers.
	 */
	private static final String	HEX_INT		= applyFormat("fpHexInteger", HexDigits);
	private static final String	HEX_DEC		= applyFormat("fpHexDecimal", HexDigits);
	private static final String	HEX_LEAD	= applyFormat("fpHexLeader", HEX_INT, HEX_DEC);
	private static final String	HEX_STRING	= applyFormat("fpHexString", HEX_LEAD, DecDigits);

	/*
	 * Floating point components.
	 */
	private static final String	FP_LEADER	= getRegex("fpLeader");
	private static final String	FP_NUM		= applyFormat("fpNumber", SIMPLE_INTDEC, SIMPLE_DEC,
			HEX_STRING);

	private static final String	fpRegex		= applyFormat("fpDouble", FP_LEADER, FP_NUM);
	public static final Pattern	floatingLiteral	= Pattern.compile("\\A" + fpRegex + "\\Z");
}