+ m = account_name_re.matcher(line);
+ if (m.find()) {
+ String acct_encoded = m.group(1);
+ String acct_name = URLDecoder.decode(acct_encoded, "UTF-8");
+ acct_name = acct_name.replace("\"", "");
+ L(String.format("found account: %s", acct_name));
+
+ profile.storeAccount(acct_name);
+ lastAccount = new LedgerAccount(acct_name);
+
+ // make sure the parent account(s) are present,
+ // synthesising them if necessary
+ String parentName = lastAccount.getParentName();
+ if (parentName != null) {
+ Stack<String> toAppend = new Stack<>();
+ while (parentName != null) {
+ if (accountNames.containsKey(parentName)) break;
+ toAppend.push(parentName);
+ parentName = new LedgerAccount(parentName)
+ .getParentName();
+ }
+ while (!toAppend.isEmpty()) {
+ String aName = toAppend.pop();
+ LedgerAccount acc = new LedgerAccount(aName);
+ accountList.add(acc);
+ L(String.format("gap-filling with %s", aName));
+ accountNames.put(aName, null);
+ profile.storeAccount(aName);
+ }
+ }
+
+ accountList.add(lastAccount);
+ accountNames.put(acct_name, null);
+
+ state = ParserState.EXPECTING_ACCOUNT_AMOUNT;
+ L("→ expecting account amount");
+ }
+ break;
+
+ case EXPECTING_ACCOUNT_AMOUNT:
+ m = account_value_re.matcher(line);
+ boolean match_found = false;
+ while (m.find()) {
+ throwIfCancelled();
+
+ match_found = true;
+ String value = m.group(1);
+ String currency = m.group(2);
+ if (currency == null) currency = "";
+ value = value.replace(',', '.');
+ L("curr=" + currency + ", value=" + value);
+ profile.storeAccountValue(lastAccount.getName(), currency,
+ Float.valueOf(value));
+ lastAccount.addAmount(Float.parseFloat(value), currency);
+ }
+
+ if (match_found) {
+ state = ParserState.EXPECTING_ACCOUNT;
+ L("→ expecting account");
+ }
+