Skip to content

Commit

Permalink
Fix QuantityType UNIT_PATTERN regex
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
  • Loading branch information
jimtng committed Oct 9, 2023
1 parent 783c57c commit 78f3124
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ public void testValidConstructors(Locale locale) {
new QuantityType<>("0E-22 m");
new QuantityType<>("10E-3");
new QuantityType<>("10E3");
new QuantityType<>("1 /s");
new QuantityType<>("1/s");
new QuantityType<>("1Ω·m");
QuantityType.valueOf("2m");
}

Expand Down

0 comments on commit 78f3124

Please sign in to comment.