Skip to content

Commit

Permalink
Added upper/lower case String? variants
Browse files Browse the repository at this point in the history
  • Loading branch information
sksamuel committed Dec 30, 2023
1 parent 775c27d commit 7ed0594
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <I, E> Parser<I, String, E>.toUppercase(): Parser<I, String, E> = 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 <I, E> Parser<I, String?, E>.toUppercase(): Parser<I, String?, E> = 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 <I, E> Parser<I, String, E>.toLowercase(): Parser<I, String, E> = 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 <I, E> Parser<I, String?, E>.toLowercase(): Parser<I, String?, E> = mapIfNotNull { it.lowercase() }

0 comments on commit 7ed0594

Please sign in to comment.