unitsofmeasurement / indriya

JSR 385 - Reference Implementation
Other
115 stars 40 forks source link

SimpleUnitFormat.parse() does not always work with prefixes #343

Open keilw opened 3 years ago

keilw commented 3 years ago

There are at least one or two cases where SimpleUnitFormat.parse() (or AbstractUnit.parse()) won't recognize a string that can be properly formatted, it seems related to prefixes where observed.

E.g. AbstractUnit.parse("dm") works just the same way as DECI(METRE).toString(), but the result of DECI(CARAT).toString() fails parsing it with AbstractUnit.parse("dct"). Note CARAT is defined by the extension module Unicode CLDR, but it should not really matter if the unit is defined by the RI itself or an extension.

cmmercer commented 2 years ago

I have also encountered this when using a custom unit (of geologic time, the "annus" with symbol "a") that I defined in my own SystemOfUnits. I took care to register a label with SimpleUnitFormat, so I can parse it when the unit does not have a prefix. But when I instantiate the unit with a metric prefix and try to parse the result of calling toString() (e.g., "Ma" or "ka") it fails.