Extracted StringExtensions

This commit is contained in:
dankl 2019-10-20 19:00:20 +02:00 committed by dankito
parent fdb8545d6b
commit 289a2032b8
2 changed files with 19 additions and 16 deletions

View File

@ -0,0 +1,17 @@
package net.dankito.fints.extensions
fun String.allIndicesOf(toFind: String): List<Int> {
val indices = mutableListOf<Int>()
var index = -1
do {
index = this.indexOf(toFind, index + 1)
if (index > -1) {
indices.add(index)
}
} while (index > -1)
return indices
}

View File

@ -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<Int> {
val indices = mutableListOf<Int>()
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)