From 8e2732de0b27c0d992d5e1b9a310729ad5e2edb7 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Fri, 12 Jun 2020 22:47:06 +0300 Subject: [PATCH] legacy text parser: add support for currency before the amount --- .../async/RetrieveTransactionsTask.java | 48 ++++++++++++++----- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java index 6afe539b..3a882743 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java @@ -67,8 +67,9 @@ public class RetrieveTransactionsTask "id=\"transaction-(\\d+)\">([\\d.-]+)"); private static final Pattern reTransactionDescription = Pattern.compile(" 0)) { + if ((currencyPost != null) && (currencyPost.length() > 0)) + return null; + currency = currencyPre; + } + else if ((currencyPost != null) && (currencyPost.length() > 0)) { + currency = currencyPost; + } + + amount = amount.replace(',', '.'); + + return new LedgerTransactionAccount(acc_name, Float.valueOf(amount), currency, null); + } + else { + return null; + } + } @Override protected void onProgressUpdate(Progress... values) { super.onProgressUpdate(values); @@ -363,18 +391,12 @@ public class RetrieveTransactionsTask // } } else { - m = reTransactionDetails.matcher(line); - if (m.find()) { - String postingStatus = m.group(1); - String acc_name = m.group(2); - String amount = m.group(3); - String currency = m.group(4); - if (currency == null) currency = ""; - amount = amount.replace(',', '.'); - transaction.addAccount(new LedgerTransactionAccount(acc_name, - Float.valueOf(amount), currency, null)); + LedgerTransactionAccount lta = parseTransactionAccountLine(line); + if (lta != null) { + transaction.addAccount(lta); L(String.format(Locale.ENGLISH, "%d: %s = %s", - transaction.getId(), acc_name, amount)); + transaction.getId(), lta.getAccountName(), + lta.getAmount())); } else throw new IllegalStateException( String.format("Can't parse transaction %d " + "details: %s", -- 2.39.5