From a3b97edd487c3d999da6082f33ef276d7e587ae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Fri, 30 Dec 2022 21:29:40 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20getNormalizedSymbol()=20for=20=C5=81=20le?= =?UTF-8?q?tter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/github/wulkanowy/sdk/scrapper/Utils.kt | 12 ++++++++---- .../github/wulkanowy/sdk/scrapper/UtilsKtTest.kt | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/UtilsKtTest.kt diff --git a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Utils.kt b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Utils.kt index 677f5d6c..8643bf37 100644 --- a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Utils.kt +++ b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Utils.kt @@ -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.normalizeRecipients() = map { it.parseName() } diff --git a/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/UtilsKtTest.kt b/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/UtilsKtTest.kt new file mode 100644 index 00000000..ae74ec27 --- /dev/null +++ b/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/UtilsKtTest.kt @@ -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()) + } +}