From 4a890a0ba7b8a0088cacc305402f0efc7352cbf6 Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 21 May 2020 00:37:45 +0200 Subject: [PATCH] Fixed getting remainder without that an exception gets thrown --- .../banking/fints/transactions/mt940/Mt940Parser.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fints4k/src/main/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt b/fints4k/src/main/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt index 98dafa19..c4f3f241 100644 --- a/fints4k/src/main/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt +++ b/fints4k/src/main/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt @@ -75,13 +75,15 @@ open class Mt940Parser : IMt940Parser { override fun parseTransactionsChunk(mt940Chunk: String): Pair, String> { try { - val singleAccountStatementsStrings = splitIntoSingleAccountStatements(mt940Chunk) + val singleAccountStatementsStrings = splitIntoSingleAccountStatements(mt940Chunk).toMutableList() + + var remainder = "" + if (singleAccountStatementsStrings.isNotEmpty() && singleAccountStatementsStrings.last().isEmpty() == false) { + remainder = singleAccountStatementsStrings.removeAt(singleAccountStatementsStrings.lastIndex) + } val transactions = singleAccountStatementsStrings.mapNotNull { parseAccountStatement(it) } - val remainder = if (singleAccountStatementsStrings.size == transactions.size + 1) singleAccountStatementsStrings.last() - else "" - return Pair(transactions, remainder) } catch (e: Exception) { log.error("Could not parse account statements from MT940 string:\n$mt940Chunk", e)