-
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.
Add string manipulation functions: .uppercase,
.lowercase
, `.capita…
…lize`
- Loading branch information
Showing
4 changed files
with
47 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ object Stdlib : LibraryExporter { | |
Text + | ||
Math + | ||
Logical + | ||
String + | ||
Logger + | ||
Flow + | ||
Data + | ||
|
38 changes: 38 additions & 0 deletions
38
stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/String.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,38 @@ | ||
package eu.iamgio.quarkdown.stdlib | ||
|
||
import eu.iamgio.quarkdown.function.value.wrappedAsValue | ||
|
||
/** | ||
* `String` stdlib module exporter. | ||
* This module handles string manipulation. | ||
*/ | ||
val String: Module = | ||
setOf( | ||
::uppercase, | ||
::lowercase, | ||
::capitalize, | ||
) | ||
|
||
/** | ||
* Converts a string to uppercase. | ||
* Example: `Hello, World!` -> `HELLO, WORLD! | ||
* @param string string to convert | ||
* @return a new uppercase string | ||
*/ | ||
fun uppercase(string: String) = string.uppercase().wrappedAsValue() | ||
|
||
/** | ||
* Converts a string to lowercase. | ||
* Example: `Hello, World!` -> `hello, world!` | ||
* @param string string to convert | ||
* @return a new lowercase string | ||
*/ | ||
fun lowercase(string: String) = string.lowercase().wrappedAsValue() | ||
|
||
/** | ||
* Capitalizes the first character of a string. | ||
* Example: `hello, world!` -> `Hello, world!` | ||
* @param string string to capitalize | ||
* @return a new string with the first character capitalized | ||
*/ | ||
fun capitalize(string: String) = string.replaceFirstChar(Char::titlecase).wrappedAsValue() |
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