Fix getNormalizedSymbol() for Ł letter

This commit is contained in:
Mikołaj Pich 2022-12-30 21:29:40 +01:00
parent 3c5a4d66ce
commit a3b97edd48
2 changed files with 22 additions and 4 deletions

View file

@ -65,13 +65,17 @@ fun getScriptParam(name: String, content: String, fallback: String = ""): String
}
}
fun String.getNormalizedSymbol(): String {
return trim().lowercase().replace("default", "").run {
fun String.getNormalizedSymbol(): String = this
.trim().lowercase()
.replace("default", "")
.run {
Normalizer.normalize(this, Normalizer.Form.NFD).run {
"\\p{InCombiningDiacriticalMarks}+".toRegex().replace(this, "")
}
}.replace("[^a-z0-9]".toRegex(), "").ifBlank { "Default" }
}
}
.replace("ł", "l")
.replace("[^a-z0-9]".toRegex(), "")
.ifBlank { "Default" }
fun List<Recipient>.normalizeRecipients() = map { it.parseName() }

View file

@ -0,0 +1,14 @@
package io.github.wulkanowy.sdk.scrapper
import org.junit.Assert.*
import org.junit.Test
class UtilsKtTest {
@Test
fun `get normalized symbol`() {
assertEquals("warszawa", "Warszawa".getNormalizedSymbol())
assertEquals("lodz", "Łódź".getNormalizedSymbol())
assertEquals("tomaszowmazowiecki", "Tomaszów Mazowiecki".getNormalizedSymbol())
}
}