From 7ed0594cad05f8430eb768e4f6d64303da2274bb Mon Sep 17 00:00:00 2001 From: sksamuel Date: Sat, 30 Dec 2023 10:28:32 -0600 Subject: [PATCH] Added upper/lower case String? variants --- .../com/sksamuel/tribune/core/strings/case.kt | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tribune-core/src/main/kotlin/com/sksamuel/tribune/core/strings/case.kt b/tribune-core/src/main/kotlin/com/sksamuel/tribune/core/strings/case.kt index 87a26dc..dba7d72 100644 --- a/tribune-core/src/main/kotlin/com/sksamuel/tribune/core/strings/case.kt +++ b/tribune-core/src/main/kotlin/com/sksamuel/tribune/core/strings/case.kt @@ -2,17 +2,34 @@ package com.sksamuel.tribune.core.strings import com.sksamuel.tribune.core.Parser import com.sksamuel.tribune.core.map +import com.sksamuel.tribune.core.mapIfNotNull /** - * Modifies a String -> String [Parser] by uppercasing the output string. + * Modifies an I -> String [Parser] by uppercasing the output string. * * @return the output of the underlying parser with the output uppercased. */ fun Parser.toUppercase(): Parser = map { it.uppercase() } /** - * Modifies a String -> String [Parser] by lowercasing the output string. + * Modifies an I -> String? [Parser] by uppercasing the output string. + * + * @return the output of the underlying parser with the output uppercased. + */ +@JvmName("toUppercaseOrNull") +fun Parser.toUppercase(): Parser = mapIfNotNull { it.uppercase() } + +/** + * Modifies an I -> String [Parser] by lowercasing the output string. * * @return the output of the underlying parser with the output lowercased. */ fun Parser.toLowercase(): Parser = map { it.lowercase() } + +/** + * Modifies an I -> String? [Parser] by lowercasing the output string. + * + * @return the output of the underlying parser with the output lowercased. + */ +@JvmName("toLowercaseOrNull") +fun Parser.toLowercase(): Parser = mapIfNotNull { it.lowercase() }