diff --git a/README.MD b/README.MD index c45f9a4..a163228 100644 --- a/README.MD +++ b/README.MD @@ -15,6 +15,7 @@ Multiplatform Kotlin library to convert strings between various case formats - kebab-case - UPPER SPACE CASE - Title Case +- Sentence case - lower space case - UPPER.DOT.CASE - dot.case diff --git a/src/commonMain/kotlin/net/pearx/kasechange/CaseFormat.kt b/src/commonMain/kotlin/net/pearx/kasechange/CaseFormat.kt index fae8f46..f807742 100644 --- a/src/commonMain/kotlin/net/pearx/kasechange/CaseFormat.kt +++ b/src/commonMain/kotlin/net/pearx/kasechange/CaseFormat.kt @@ -34,6 +34,8 @@ enum class CaseFormat(caseFormatterConfig: CaseFormatterConfig, wordSplitterConf UPPER_SPACE(CaseFormatterConfig(true, " "), WordSplitterConfig(setOf(' '))), /** Title Case */ CAPITALIZED_SPACE(CaseFormatterConfig(false, " ", wordCapitalize = true, firstWordCapitalize = true), WordSplitterConfig(setOf(' '))), + /** Sentence case */ + SENTENCE_SPACE(CaseFormatterConfig(false, " ", wordCapitalize = false, firstWordCapitalize = true), WordSplitterConfig(setOf(' '))), /** lower space case */ LOWER_SPACE(CaseFormatterConfig(false, " "), WordSplitterConfig(setOf(' '))), /** UPPER.DOT.CASE */ diff --git a/src/commonMain/kotlin/net/pearx/kasechange/StringExtensions.kt b/src/commonMain/kotlin/net/pearx/kasechange/StringExtensions.kt index 5ac076d..f7fad81 100644 --- a/src/commonMain/kotlin/net/pearx/kasechange/StringExtensions.kt +++ b/src/commonMain/kotlin/net/pearx/kasechange/StringExtensions.kt @@ -54,6 +54,9 @@ fun String.toUpperSpaceCase(from: WordSplitter = universalWordSplitter()) = toCa /** Returns a copy of this string converted to Title Case by splitting it into multiple words using [specified][from] [WordSplitter] and joining them using [CaseFormat.CAPITALIZED_SPACE].. */ fun String.toTitleCase(from: WordSplitter = universalWordSplitter()) = toCase(CaseFormat.CAPITALIZED_SPACE, from) +/** Returns a copy of this string converted to Sentence case by splitting it into multiple words using [specified][from] [WordSplitter] and joining them using [CaseFormat.SENTENCE_SPACE].. */ +fun String.toSentenceCase(from: WordSplitter = universalWordSplitter()) = toCase(CaseFormat.SENTENCE_SPACE, from) + /** Returns a copy of this string converted to lower space case by splitting it into multiple words using [specified][from] [WordSplitter] and joining them using [CaseFormat.LOWER_SPACE].. */ fun String.toLowerSpaceCase(from: WordSplitter = universalWordSplitter()) = toCase(CaseFormat.LOWER_SPACE, from) diff --git a/src/commonTest/kotlin/net/pearx/kasechange/test/CaseFormatterTest.kt b/src/commonTest/kotlin/net/pearx/kasechange/test/CaseFormatterTest.kt index f307b58..9fc8688 100644 --- a/src/commonTest/kotlin/net/pearx/kasechange/test/CaseFormatterTest.kt +++ b/src/commonTest/kotlin/net/pearx/kasechange/test/CaseFormatterTest.kt @@ -61,6 +61,11 @@ class CaseFormatterTest { assertEquals("Xml Http Request V2 Updated", CaseFormat.CAPITALIZED_SPACE.format("XmL", "http", "reQuEST", "v2", "Updated")) } + @Test + fun testSentence() { + assertEquals("Xml http request v2 updated", CaseFormat.SENTENCE_SPACE.format("XmL", "http", "reQuEST", "v2", "Updated")) + } + @Test fun testDot() { assertEquals("xml.http.request.v2.updated", CaseFormat.LOWER_DOT.format("XML", "http", "reQuEST", "V2", "Updated")) diff --git a/src/commonTest/kotlin/net/pearx/kasechange/test/ComplexTest.kt b/src/commonTest/kotlin/net/pearx/kasechange/test/ComplexTest.kt index b6884dc..d03851d 100644 --- a/src/commonTest/kotlin/net/pearx/kasechange/test/ComplexTest.kt +++ b/src/commonTest/kotlin/net/pearx/kasechange/test/ComplexTest.kt @@ -59,6 +59,11 @@ class ComplexTest { assertEquals("Xml Http Request V2 Updated", "xml_http_request_v2_updated".toTitleCase(CaseFormat.LOWER_UNDERSCORE)) } + @Test + fun testSentence() { + assertEquals("Xml http request v2 updated", "xml_http_request_v2_updated".toSentenceCase(CaseFormat.LOWER_UNDERSCORE)) + } + @Test fun testDot() { assertEquals("xml.http.request.v2.updated", "xml_http_request_v2_updated".toDotCase(CaseFormat.LOWER_UNDERSCORE)) diff --git a/src/commonTest/kotlin/net/pearx/kasechange/test/UniversalWordSplitter2Test.kt b/src/commonTest/kotlin/net/pearx/kasechange/test/UniversalWordSplitter2Test.kt index d3a4cf6..f413c93 100644 --- a/src/commonTest/kotlin/net/pearx/kasechange/test/UniversalWordSplitter2Test.kt +++ b/src/commonTest/kotlin/net/pearx/kasechange/test/UniversalWordSplitter2Test.kt @@ -58,6 +58,11 @@ class UniversalWordSplitter2Test { assertEquals(listOf("XML", "Http", "Request", "V2", "Updated"), "XML Http Request V2 Updated".splitToWords(universalWordSplitter(false))) } + @Test + fun testSentence() { + assertEquals(listOf("Xml", "http", "request", "v2", "updated"), "Xml http request v2 updated".splitToWords(universalWordSplitter(false))) + } + @Test fun testDot() { assertEquals(listOf("xml", "http", "request", "v2", "updated"), "xml.http.request.v2.updated".splitToWords(universalWordSplitter(false))) diff --git a/src/commonTest/kotlin/net/pearx/kasechange/test/UniversalWordSplitterTest.kt b/src/commonTest/kotlin/net/pearx/kasechange/test/UniversalWordSplitterTest.kt index ca36ef0..d9bdd1e 100644 --- a/src/commonTest/kotlin/net/pearx/kasechange/test/UniversalWordSplitterTest.kt +++ b/src/commonTest/kotlin/net/pearx/kasechange/test/UniversalWordSplitterTest.kt @@ -57,6 +57,11 @@ class UniversalWordSplitterTest { assertEquals(listOf("XML", "Request", "V2", "Updated"), "XML Request V2 Updated".splitToWords()) } + @Test + fun testSentence() { + assertEquals(listOf("Xml", "request", "v", "2", "updated"), "Xml request v2 updated".splitToWords()) + } + @Test fun testDot() { assertEquals(listOf("xml", "request", "V2", "updated"), "xml.request.V2.updated".splitToWords()) diff --git a/src/commonTest/kotlin/net/pearx/kasechange/test/WordSplitterTest.kt b/src/commonTest/kotlin/net/pearx/kasechange/test/WordSplitterTest.kt index 807c670..84c01fe 100644 --- a/src/commonTest/kotlin/net/pearx/kasechange/test/WordSplitterTest.kt +++ b/src/commonTest/kotlin/net/pearx/kasechange/test/WordSplitterTest.kt @@ -59,6 +59,11 @@ class WordSplitterTest { assertEquals(listOf("XML", "Request", "V2", "Updated"), "XML Request V2 Updated".splitToWords(CaseFormat.CAPITALIZED_SPACE)) } + @Test + fun testSentence() { + assertEquals(listOf("Xml", "request", "v2", "updated"), "Xml request v2 updated".splitToWords(CaseFormat.CAPITALIZED_SPACE)) + } + @Test fun testDot() { assertEquals(listOf("xml", "request", "v2", "updated"), "xml.request.v2.updated".splitToWords(CaseFormat.LOWER_DOT))