Extracted convertReservedXmlCharacters() and convertDiacritics()

This commit is contained in:
dankito 2020-10-05 00:37:00 +02:00
parent 08d3cfbd66
commit 97e7d44a47
2 changed files with 14 additions and 9 deletions

View File

@ -5,14 +5,16 @@ interface ISepaMessageCreator {
fun createXmlFile(messageTemplate: PaymentInformationMessages, replacementStrings: Map<String, String>): String fun createXmlFile(messageTemplate: PaymentInformationMessages, replacementStrings: Map<String, String>): String
fun convertDiacriticsAndReservedXmlCharactersAndCheckIfContainsOnlyAllowedCharacters(stringToTest: String): Boolean {
val convertedString = convertDiacriticsAndReservedXmlCharacters(stringToTest)
return containsOnlyAllowedCharacters(convertedString)
}
fun containsOnlyAllowedCharacters(stringToTest: String): Boolean fun containsOnlyAllowedCharacters(stringToTest: String): Boolean
fun convertDiacriticsAndReservedXmlCharacters(input: String): String fun convertDiacriticsAndReservedXmlCharacters(input: String): String {
var converted = convertDiacritics(input)
return convertReservedXmlCharacters(converted)
}
fun convertReservedXmlCharacters(input: String): String
fun convertDiacritics(input: String): String
} }

View File

@ -37,7 +37,7 @@ open class SepaMessageCreator : ISepaMessageCreator {
&& convertDiacriticsAndReservedXmlCharacters(stringToTest) == stringToTest && convertDiacriticsAndReservedXmlCharacters(stringToTest) == stringToTest
} }
override fun convertDiacriticsAndReservedXmlCharacters(input: String): String { override fun convertReservedXmlCharacters(input: String): String {
// TODO: add other replacement strings // TODO: add other replacement strings
return input return input
.replace("\"", "&quot;") .replace("\"", "&quot;")
@ -45,8 +45,11 @@ open class SepaMessageCreator : ISepaMessageCreator {
.replace("&", "&amp;") .replace("&", "&amp;")
.replace("<", "&lt;") .replace("<", "&lt;")
.replace(">", "&gt;") .replace(">", "&gt;")
}
override fun convertDiacritics(input: String): String {
return input
// convert diacritics
.replace("á", "a", true) .replace("á", "a", true)
.replace("à", "a", true) .replace("à", "a", true)
.replace("â", "a", true) .replace("â", "a", true)