Skip to content

Commit

Permalink
Merge pull request #9 from GregHib/feature/add-sentence-case
Browse files Browse the repository at this point in the history
Add sentence case format
  • Loading branch information
mrapplexz authored Apr 24, 2023
2 parents 09ad661 + ff12f1d commit 6a0ee68
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/commonMain/kotlin/net/pearx/kasechange/CaseFormat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 6a0ee68

Please sign in to comment.