Simplified removing new line characters
This commit is contained in:
parent
96454a742d
commit
08b21980f9
|
@ -74,6 +74,7 @@ open class Mt940Parser : IMt940Parser {
|
|||
|
||||
protected open fun splitIntoSingleAccountStatements(mt940String: String): List<String> {
|
||||
return mt940String.split("\n-")
|
||||
.map { it.replace("\n", "").replace("\r", "") }
|
||||
}
|
||||
|
||||
|
||||
|
@ -102,7 +103,7 @@ open class Mt940Parser : IMt940Parser {
|
|||
|
||||
while (matcher.find()) {
|
||||
if (lastMatchEnd > 0) {
|
||||
val previousStatement = accountStatementString.substring(lastMatchEnd, matcher.start()).replace("\n", "")
|
||||
val previousStatement = accountStatementString.substring(lastMatchEnd, matcher.start())
|
||||
result.add(Pair(lastMatchedCode, previousStatement))
|
||||
}
|
||||
|
||||
|
@ -111,7 +112,7 @@ open class Mt940Parser : IMt940Parser {
|
|||
}
|
||||
|
||||
if (lastMatchEnd > 0) {
|
||||
val previousStatement = accountStatementString.substring(lastMatchEnd, accountStatementString.length).replace("\n", "")
|
||||
val previousStatement = accountStatementString.substring(lastMatchEnd, accountStatementString.length)
|
||||
result.add(Pair(lastMatchedCode, previousStatement))
|
||||
}
|
||||
|
||||
|
@ -199,7 +200,7 @@ open class Mt940Parser : IMt940Parser {
|
|||
val turnover = parseTurnover(pair.second)
|
||||
|
||||
val nextPair = if (index < fieldsByCode.size - 1) fieldsByCode.get(index + 1) else null
|
||||
val details = if (nextPair?.first == TransactionDetailsCode) parseNullableTransactionDetails(nextPair?.second) else null
|
||||
val details = if (nextPair?.first == TransactionDetailsCode) parseNullableTransactionDetails(nextPair.second) else null
|
||||
|
||||
transactions.add(Transaction(turnover, details))
|
||||
}
|
||||
|
@ -254,24 +255,24 @@ open class Mt940Parser : IMt940Parser {
|
|||
customerReference, bankReference)
|
||||
}
|
||||
|
||||
protected open fun parseNullableTransactionDetails(fieldValue: String): TransactionDetails? {
|
||||
protected open fun parseNullableTransactionDetails(detailsString: String): TransactionDetails? {
|
||||
try {
|
||||
val details = parseTransactionDetails(fieldValue)
|
||||
val details = parseTransactionDetails(detailsString)
|
||||
|
||||
mapUsage(details)
|
||||
|
||||
return details
|
||||
} catch (e: Exception) {
|
||||
log.error("Could not parse transaction details from field value '$fieldValue'", e)
|
||||
log.error("Could not parse transaction details from field value '$detailsString'", e)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
private fun parseTransactionDetails(fieldValue: String): TransactionDetails {
|
||||
private fun parseTransactionDetails(detailsString: String): TransactionDetails {
|
||||
// e. g. starts with 0 -> Inlandszahlungsverkehr, starts with '3' -> Wertpapiergeschäft
|
||||
// see Finanzdatenformate p. 209 - 215
|
||||
val geschaeftsvorfallCode = fieldValue.substring(0, 2) // TODO: may map
|
||||
val geschaeftsvorfallCode = detailsString.substring(0, 2) // TODO: may map
|
||||
|
||||
val usage = StringBuilder("")
|
||||
val otherPartyName = StringBuilder("")
|
||||
|
@ -281,7 +282,7 @@ open class Mt940Parser : IMt940Parser {
|
|||
var primaNotaNumber: String? = null
|
||||
var textKeySupplement: String? = null
|
||||
|
||||
fieldValue.replace("\r", "").replace("\n", "").substring(3).split('?').forEach { subField ->
|
||||
detailsString.substring(3).split('?').forEach { subField ->
|
||||
if (subField.isNotEmpty()) {
|
||||
val fieldCode = subField.substring(0, 2).toInt()
|
||||
val fieldValue = subField.substring(2)
|
||||
|
|
Loading…
Reference in New Issue