From: Damyan Ivanov Date: Fri, 12 Jun 2020 19:47:06 +0000 (+0300) Subject: legacy text parser: add support for currency before the amount X-Git-Tag: v0.14.0~38 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=8e2732de0b27c0d992d5e1b9a310729ad5e2edb7;p=mobile-ledger.git legacy text parser: add support for currency before the amount --- 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",