From 497b82ce09c01d7e87ee6ce2116eb1f71ee5b07a Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 17 Sep 2020 11:57:19 +0200 Subject: [PATCH] Started to implement to remove unnecessary spaces in usage, but now having to few --- .../utils/multiplatform/CommonExtensions.kt | 6 +++++ .../fints/transactions/mt940/Mt940Parser.kt | 22 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/CommonExtensions.kt b/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/CommonExtensions.kt index cb65e1b5..5c976b45 100644 --- a/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/CommonExtensions.kt +++ b/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/CommonExtensions.kt @@ -1,6 +1,12 @@ package net.dankito.utils.multiplatform +val Char.isLowerCase: Boolean + get() = toLowerCase() == this + +val Char.isUpperCase: Boolean + get() = isLowerCase == false + fun Throwable?.getInnerExceptionMessage(maxDepth: Int = 3): String? { return this?.getInnerException(maxDepth)?.message diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt index 50c745b9..f438d219 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt @@ -5,6 +5,7 @@ import net.dankito.banking.fints.transactions.mt940.model.* import net.dankito.utils.multiplatform.Date import net.dankito.utils.multiplatform.DateFormatter import net.dankito.utils.multiplatform.Month +import net.dankito.utils.multiplatform.isUpperCase import net.dankito.utils.multiplatform.log.LoggerFactory @@ -335,7 +336,7 @@ open class Mt940Parser : IMt940Parser { } } - val usage = if (isFormattedUsage(usageParts)) usageParts.joinToString("") + val usage = if (isFormattedUsage(usageParts)) joinUsageParts(usageParts) else usageParts.joinToString(" ") val otherPartyNameString = if (otherPartyName.isEmpty()) null else otherPartyName.toString() @@ -346,6 +347,25 @@ open class Mt940Parser : IMt940Parser { ) } + protected open fun joinUsageParts(usageParts: List): String { + val usage = StringBuilder() + + usageParts.firstOrNull()?.let { + usage.append(it) + } + + for (i in 1..usageParts.size - 1) { + val part = usageParts[i] + if (part.isNotEmpty() && part.first().isUpperCase && usageParts[i - 1].last().isUpperCase == false) { + usage.append(" ") + } + + usage.append(part) + } + + return usage.toString() + } + protected open fun isFormattedUsage(usageParts: List): Boolean { return usageParts.any { UsageTypeRegex.find(it) != null } }