Fix QuantityType UNIT_PATTERN regex (#3841)
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>pull/3842/head
parent
783c57cbb9
commit
e9d969c31d
|
@ -70,11 +70,11 @@ public class QuantityType<T extends Quantity<T>> extends Number
|
|||
public static final QuantityType<Dimensionless> ZERO = new QuantityType<>(0, AbstractUnit.ONE);
|
||||
public static final QuantityType<Dimensionless> ONE = new QuantityType<>(1, AbstractUnit.ONE);
|
||||
|
||||
// Regular expression to split unit from value. Split on any blank character, even none (\\s*)
|
||||
// which occurs after a digit (?<=\\d) and before a "unit" character ?=[a-zA-Z°µ\u03BC%']
|
||||
// which itself must not be preceded by plus/minus digit (?![\\+\\-]?\\d).
|
||||
// Regular expression to split unit from value. Split on any blank character, or
|
||||
// between a digit (?<=\\d) and a non-digit character (?=\\D)
|
||||
// which must not be preceded by plus/minus digit (?![\\+\\-]?\\d).
|
||||
// The latter would be an exponent from the scalar value.
|
||||
private static final String UNIT_PATTERN = "(?<=\\d)\\s*(?=[a-zA-Z°µ\u03BC%'](?![\\+\\-]?\\d))";
|
||||
private static final String UNIT_PATTERN = "\\s+|(?<=\\d)(?=\\D(?![\\+\\-]?\\d))";
|
||||
|
||||
static {
|
||||
UnitInitializer.init();
|
||||
|
|
|
@ -143,6 +143,11 @@ public class QuantityTypeTest {
|
|||
new QuantityType<>("0E-22 m");
|
||||
new QuantityType<>("10E-3");
|
||||
new QuantityType<>("10E3");
|
||||
new QuantityType<>("1 /s");
|
||||
new QuantityType<>("1/s");
|
||||
new QuantityType<>("1Ω·m");
|
||||
new QuantityType<>("1 Ω·m");
|
||||
new QuantityType<>("1.5E2Ω·m");
|
||||
QuantityType.valueOf("2m");
|
||||
}
|
||||
|
||||
|
@ -158,6 +163,10 @@ public class QuantityTypeTest {
|
|||
assertEquals(QuantityType.valueOf("1.1e3\u03BCm"), QuantityType.valueOf("1.1E3 µm"));
|
||||
assertEquals(QuantityType.valueOf("1.1e3 \u00B5m"), QuantityType.valueOf("1.1E3 µm"));
|
||||
assertEquals(QuantityType.valueOf("1.1e3\u00B5m"), QuantityType.valueOf("1.1E3 µm"));
|
||||
assertEquals(QuantityType.valueOf("1.1e3Ω·m"), QuantityType.valueOf("1.1E3 Ω·m"));
|
||||
assertEquals(QuantityType.valueOf("1.1e3 Ω·m"), QuantityType.valueOf("1.1E3 Ω·m"));
|
||||
assertEquals(QuantityType.valueOf("1.1e3/s"), QuantityType.valueOf("1.1E3 /s"));
|
||||
assertEquals(QuantityType.valueOf("1.1e3 /s"), QuantityType.valueOf("1.1E3 /s"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
|
|
Loading…
Reference in New Issue