diff --git a/stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/Stdlib.kt b/stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/Stdlib.kt index 7f306ed4..3a00b286 100644 --- a/stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/Stdlib.kt +++ b/stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/Stdlib.kt @@ -24,6 +24,7 @@ object Stdlib : LibraryExporter { Text + Math + Logical + + String + Logger + Flow + Data + diff --git a/stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/String.kt b/stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/String.kt new file mode 100644 index 00000000..f62a1b44 --- /dev/null +++ b/stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/String.kt @@ -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() diff --git a/stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/Text.kt b/stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/Text.kt index 22638b3a..8abb2476 100644 --- a/stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/Text.kt +++ b/stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/Text.kt @@ -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( diff --git a/test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt b/test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt index 76a1fe55..10574fe9 100644 --- a/test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt +++ b/test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt @@ -193,6 +193,13 @@ class FullPipelineTest { assertEquals("

A

B

", it) } + execute("Hello, World! .uppercase {Hello, World!} .lowercase {Hello, World!} .capitalize {hello, world!}") { + assertEquals( + "

Hello, World! HELLO, WORLD! hello, world! Hello, world!

", + it, + ) + } + execute( """ .doclang {Italian}