-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: use
StringCase
strategy for numbering strategies instead …
…of one numbering per case
- Loading branch information
Showing
5 changed files
with
78 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
core/src/main/kotlin/eu/iamgio/quarkdown/util/StringCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package eu.iamgio.quarkdown.util | ||
|
||
/** | ||
* A general purpose strategy to transform a string to a specific case type. | ||
*/ | ||
sealed interface StringCase { | ||
/** | ||
* Transforms a [string] according to the case. | ||
* @return transformed string | ||
*/ | ||
fun transform(string: String): String | ||
|
||
/** | ||
* Uppercase. `Hello` -> `HELLO` | ||
*/ | ||
data object Upper : StringCase { | ||
override fun transform(string: String) = string.uppercase() | ||
} | ||
|
||
/** | ||
* Lowercase. `Hello` -> `hello` | ||
*/ | ||
data object Lower : StringCase { | ||
override fun transform(string: String) = string.lowercase() | ||
} | ||
|
||
/** | ||
* Capitalize. `hello` -> `Hello` | ||
*/ | ||
data object Capitalize : StringCase { | ||
override fun transform(string: String) = string.replaceFirstChar(Char::titlecase) | ||
} | ||
} | ||
|
||
/** | ||
* Transforms [this] string to a specific case. | ||
* @return the transformed string | ||
*/ | ||
fun String.case(case: StringCase) = case.transform(this) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters