From 289a2032b8a851e6f52a04537bb882ef2cb54bc8 Mon Sep 17 00:00:00 2001 From: dankl Date: Sun, 20 Oct 2019 19:00:20 +0200 Subject: [PATCH] Extracted StringExtensions --- .../fints/extensions/StringExtensions.kt | 17 +++++++++++++++++ .../dankito/fints/response/ResponseParser.kt | 18 ++---------------- 2 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 fints4javaLib/src/main/kotlin/net/dankito/fints/extensions/StringExtensions.kt diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/extensions/StringExtensions.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/extensions/StringExtensions.kt new file mode 100644 index 00000000..169306d8 --- /dev/null +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/extensions/StringExtensions.kt @@ -0,0 +1,17 @@ +package net.dankito.fints.extensions + + +fun String.allIndicesOf(toFind: String): List { + val indices = mutableListOf() + var index = -1 + + do { + index = this.indexOf(toFind, index + 1) + + if (index > -1) { + indices.add(index) + } + } while (index > -1) + + return indices +} \ No newline at end of file diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/ResponseParser.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/ResponseParser.kt index f428b435..8d2f3214 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/ResponseParser.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/ResponseParser.kt @@ -1,5 +1,6 @@ package net.dankito.fints.response +import net.dankito.fints.extensions.allIndicesOf import net.dankito.fints.messages.Separators import net.dankito.fints.messages.datenelemente.abgeleiteteformate.Datum import net.dankito.fints.messages.datenelemente.abgeleiteteformate.Uhrzeit @@ -509,7 +510,7 @@ open class ResponseParser @JvmOverloads constructor( } } - val separatorIndices = allIndicesOf(dataString, separator) + val separatorIndices = dataString.allIndicesOf(separator) .filter { isCharacterMasked(it, dataString) == false } .filter { isInRange(it, binaryDataRanges) == false } @@ -561,21 +562,6 @@ open class ResponseParser @JvmOverloads constructor( return false } - protected open fun allIndicesOf(string: String, toFind: String): List { - val indices = mutableListOf() - var index = -1 - - do { - index = string.indexOf(toFind, index + 1) - - if (index > -1) { - indices.add(index) - } - } while (index > -1) - - return indices - } - protected open fun parseStringToNullIfEmpty(string: String): String? { val parsedString = parseString(string)