Implemented replacing diacritics and reserved XML characters in SEPA messages
This commit is contained in:
parent
fc94b47fca
commit
e18ffb8a83
|
@ -20,7 +20,7 @@ import java.util.regex.Pattern
|
||||||
open class SepaMessageCreator : ISepaMessageCreator {
|
open class SepaMessageCreator : ISepaMessageCreator {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val AllowedSepaCharacters = "A-Za-z0-9\\?,\\-\\+\\.,:/\\(\\)\'\" "
|
const val AllowedSepaCharacters = "A-Za-z0-9\\?,\\-\\+\\.,:/\\(\\)\'\" (&\\w{2,4};)"
|
||||||
|
|
||||||
val AllowedSepaCharactersPattern: Pattern = Pattern.compile("^[$AllowedSepaCharacters]*$")
|
val AllowedSepaCharactersPattern: Pattern = Pattern.compile("^[$AllowedSepaCharacters]*$")
|
||||||
|
|
||||||
|
@ -39,7 +39,9 @@ open class SepaMessageCreator : ISepaMessageCreator {
|
||||||
|
|
||||||
|
|
||||||
override fun containsOnlyAllowedCharacters(stringToTest: String): Boolean {
|
override fun containsOnlyAllowedCharacters(stringToTest: String): Boolean {
|
||||||
return AllowedSepaCharactersPattern.matcher(stringToTest).matches()
|
val convertedString = convertToAllowedCharacters(stringToTest)
|
||||||
|
|
||||||
|
return AllowedSepaCharactersPattern.matcher(convertedString).matches()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun convertToAllowedCharacters(input: String): String {
|
override fun convertToAllowedCharacters(input: String): String {
|
||||||
|
@ -50,6 +52,41 @@ open class SepaMessageCreator : ISepaMessageCreator {
|
||||||
.replace("&", "&")
|
.replace("&", "&")
|
||||||
.replace("<", "<")
|
.replace("<", "<")
|
||||||
.replace(">", ">")
|
.replace(">", ">")
|
||||||
|
|
||||||
|
// convert diacritics
|
||||||
|
.replace("á", "a", true)
|
||||||
|
.replace("à", "a", true)
|
||||||
|
.replace("â", "a", true)
|
||||||
|
.replace("ã", "a", true)
|
||||||
|
.replace("ä", "a", true)
|
||||||
|
.replace("å", "a", true)
|
||||||
|
|
||||||
|
.replace("é", "e", true)
|
||||||
|
.replace("è", "e", true)
|
||||||
|
.replace("ê", "e", true)
|
||||||
|
.replace("ë", "e", true)
|
||||||
|
|
||||||
|
.replace("í", "i", true)
|
||||||
|
.replace("ì", "i", true)
|
||||||
|
.replace("î", "i", true)
|
||||||
|
.replace("ï", "i", true)
|
||||||
|
|
||||||
|
.replace("ó", "o", true)
|
||||||
|
.replace("ò", "o", true)
|
||||||
|
.replace("ô", "o", true)
|
||||||
|
.replace("õ", "o", true)
|
||||||
|
.replace("ö", "o", true)
|
||||||
|
|
||||||
|
.replace("ú", "u", true)
|
||||||
|
.replace("ù", "u", true)
|
||||||
|
.replace("û", "u", true)
|
||||||
|
.replace("ũ", "u", true)
|
||||||
|
.replace("ü", "u", true)
|
||||||
|
|
||||||
|
.replace("ç", "u", true)
|
||||||
|
.replace("č", "u", true)
|
||||||
|
.replace("ñ", "u", true)
|
||||||
|
.replace("ß", "ss", true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -232,11 +232,11 @@ open class TransferMoneyDialog : DialogFragment() {
|
||||||
protected open fun transferMoney() {
|
protected open fun transferMoney() {
|
||||||
getEnteredAmount()?.let { amount -> // should only come at this stage when a valid amount has been entered
|
getEnteredAmount()?.let { amount -> // should only come at this stage when a valid amount has been entered
|
||||||
val data = TransferMoneyData(
|
val data = TransferMoneyData(
|
||||||
edtxtRemitteeName.text.toString(),
|
inputValidator.convertToAllowedSepaCharacters(edtxtRemitteeName.text.toString()),
|
||||||
edtxtRemitteeIban.text.toString().replace(" ", ""),
|
edtxtRemitteeIban.text.toString().replace(" ", ""),
|
||||||
edtxtRemitteeBic.text.toString().replace(" ", ""),
|
edtxtRemitteeBic.text.toString().replace(" ", ""),
|
||||||
amount,
|
amount,
|
||||||
edtxtUsage.text.toString(),
|
inputValidator.convertToAllowedSepaCharacters(edtxtUsage.text.toString()),
|
||||||
chkbxInstantPayment.isChecked
|
chkbxInstantPayment.isChecked
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,11 @@ open class InputValidator {
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun getInvalidSepaCharacters(string: String): String {
|
open fun getInvalidSepaCharacters(string: String): String {
|
||||||
return getInvalidCharacters(string, InvalidSepaCharactersPattern)
|
return getInvalidCharacters(convertToAllowedSepaCharacters(string), InvalidSepaCharactersPattern)
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun convertToAllowedSepaCharacters(string: String): String {
|
||||||
|
return sepaMessageCreator.convertToAllowedCharacters(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue