now handling single qoutes before numbers when decoding UIDs and currencies
This commit is contained in:
parent
01f22b94a2
commit
8bf68f5d66
|
@ -56,8 +56,11 @@ public class StringDecoder {
|
||||||
public static double decodeCurrency(String currency) throws IllegalArgumentException, NullPointerException {
|
public static double decodeCurrency(String currency) throws IllegalArgumentException, NullPointerException {
|
||||||
Objects.requireNonNull(currency);
|
Objects.requireNonNull(currency);
|
||||||
|
|
||||||
|
// trim and cut out weird leading single quotes for numbers
|
||||||
|
var preparedUID = currency.trim().replaceAll("^\\s*['‘`](?=\\d)", "");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return LOCAL_NUMBER_FORMAT.parse(currency.trim()).doubleValue();
|
return LOCAL_NUMBER_FORMAT.parse(preparedUID).doubleValue();
|
||||||
} catch (ParseException ex) {
|
} catch (ParseException ex) {
|
||||||
throw new IllegalArgumentException("Not a valid currency in german locale: " + currency, ex);
|
throw new IllegalArgumentException("Not a valid currency in german locale: " + currency, ex);
|
||||||
}
|
}
|
||||||
|
@ -74,10 +77,13 @@ public class StringDecoder {
|
||||||
public static int decodeUniqueIdentificationNumber(String number) throws IllegalArgumentException, NullPointerException {
|
public static int decodeUniqueIdentificationNumber(String number) throws IllegalArgumentException, NullPointerException {
|
||||||
Objects.requireNonNull(number);
|
Objects.requireNonNull(number);
|
||||||
|
|
||||||
|
// trim and cut out weird leading single quotes for numbers
|
||||||
|
var preparedUID = number.trim().replaceAll("^\\s*['‘`](?=\\d)", "");
|
||||||
|
|
||||||
// check if the string is a valid unsigned number
|
// check if the string is a valid unsigned number
|
||||||
try {
|
try {
|
||||||
LOCAL_NUMBER_FORMAT.setParseIntegerOnly(true);
|
LOCAL_NUMBER_FORMAT.setParseIntegerOnly(true);
|
||||||
var serialNumber = LOCAL_NUMBER_FORMAT.parse(number.trim());
|
var serialNumber = LOCAL_NUMBER_FORMAT.parse(preparedUID);
|
||||||
LOCAL_NUMBER_FORMAT.setParseIntegerOnly(false);
|
LOCAL_NUMBER_FORMAT.setParseIntegerOnly(false);
|
||||||
|
|
||||||
if (serialNumber.intValue() < 0)
|
if (serialNumber.intValue() < 0)
|
||||||
|
|
Loading…
Reference in New Issue