Skip to content

Commit

Permalink
Update comment and add test for unicode character for micro
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 7, 2023
1 parent b027633 commit c4bbd56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ 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°µ%'] which itself must not be preceded by plus/minus digit (?![\\+\\-]?\\d).
// The later would be an exponent from the scalar value.
// 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\u00B5%']
// which itself 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\u00B5%'](?![\\+\\-]?\\d))";

static {
Expand Down Expand Up @@ -297,7 +297,7 @@ public Dimension getDimension() {
* change the dimension.
*
* @param targetUnit the unit to which this {@link QuantityType} will be converted to.
* @return the new {@link QuantityType} in the given {@link Unit} or {@code null} in case of an erro.
* @return the new {@link QuantityType} in the given {@link Unit} or {@code null} in case of an error.
*/
public @Nullable QuantityType<?> toInvertibleUnit(Unit<?> targetUnit) {
// only invert if unit is not equal and inverse is compatible and targetUnit is not ONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ public void testLowerCaseExponents() {
assertEquals(QuantityType.valueOf("1.1e3m"), QuantityType.valueOf("1.1E3 m"));
assertEquals(QuantityType.valueOf("1.1e3m³"), QuantityType.valueOf("1.1E3 m³"));
assertEquals(QuantityType.valueOf("1.1e3m·cm"), QuantityType.valueOf("1.1E3 m·cm"));
assertEquals(QuantityType.valueOf("1.1e3 \u03BCW"), QuantityType.valueOf("1.1E3 µW"));
assertEquals(QuantityType.valueOf("1.1e3\u03BCW"), QuantityType.valueOf("1.1E3 µW"));
assertEquals(QuantityType.valueOf("1.1e3 \u00B5m"), QuantityType.valueOf("1.1E3 µm"));
assertEquals(QuantityType.valueOf("1.1e3\u00B5m"), QuantityType.valueOf("1.1E3 µm"));
}

@ParameterizedTest
Expand Down

0 comments on commit c4bbd56

Please sign in to comment.