From 8bf68f5d66180d62a448d6f6bd0f395acbd516a7 Mon Sep 17 00:00:00 2001 From: teridax Date: Wed, 12 Jul 2023 17:42:35 +0200 Subject: [PATCH] now handling single qoutes before numbers when decoding UIDs and currencies --- src/me/teridax/jcash/decode/StringDecoder.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/me/teridax/jcash/decode/StringDecoder.java b/src/me/teridax/jcash/decode/StringDecoder.java index c632dc8..86b7cd3 100644 --- a/src/me/teridax/jcash/decode/StringDecoder.java +++ b/src/me/teridax/jcash/decode/StringDecoder.java @@ -56,8 +56,11 @@ public class StringDecoder { public static double decodeCurrency(String currency) throws IllegalArgumentException, NullPointerException { Objects.requireNonNull(currency); + // trim and cut out weird leading single quotes for numbers + var preparedUID = currency.trim().replaceAll("^\\s*['‘`](?=\\d)", ""); + try { - return LOCAL_NUMBER_FORMAT.parse(currency.trim()).doubleValue(); + return LOCAL_NUMBER_FORMAT.parse(preparedUID).doubleValue(); } catch (ParseException 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 { 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 try { 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); if (serialNumber.intValue() < 0)