Skip to content

Commit

Permalink
Add string manipulation functions: .uppercase, .lowercase, `.capita…
Browse files Browse the repository at this point in the history
…lize`
  • Loading branch information
iamgio committed Oct 10, 2024
1 parent 10802cc commit 855f014
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ object Stdlib : LibraryExporter {
Text +
Math +
Logical +
String +
Logger +
Flow +
Data +
Expand Down
38 changes: 38 additions & 0 deletions stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/String.kt
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()
2 changes: 1 addition & 1 deletion stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/Text.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import eu.iamgio.quarkdown.misc.color.Color

/**
* `Text` stdlib module exporter.
* This module handles text formatting and manipulation.
* This module handles text formatting.
*/
val Text: Module =
setOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ class FullPipelineTest {
assertEquals("<p>A <div style=\"width: 1.0cm; height: 3.0mm;\"></div> B</p>", it)
}

execute("Hello, World! .uppercase {Hello, World!} .lowercase {Hello, World!} .capitalize {hello, world!}") {
assertEquals(
"<p>Hello, World! HELLO, WORLD! hello, world! Hello, world!</p>",
it,
)
}

execute(
"""
.doclang {Italian}
Expand Down

0 comments on commit 855f014

Please sign in to comment.