Skip to content

There functions are similar to toupper(), tolower() and chartr(), but they keep the ANSI colors of the string.

Usage

ansi_toupper(x)

ansi_tolower(x)

ansi_chartr(old, new, x)

Arguments

x

Input string. May have ANSI colors and styles.

old

a character string specifying the characters to be translated. If a character vector of length 2 or more is supplied, the first element is used with a warning.

new

a character string specifying the translations. If a character vector of length 2 or more is supplied, the first element is used with a warning.

Value

Character vector of the same length as x, containing the translated strings. ANSI styles are retained.

Examples

ansi_toupper(col_red("Uppercase"))
#> <cli_ansi_string>
#> [1] UPPERCASE

ansi_tolower(col_red("LowerCase"))
#> <cli_ansi_string>
#> [1] lowercase

x <- paste0(col_green("MiXeD"), col_red(" cAsE 123"))
ansi_chartr("iXs", "why", x)
#> <cli_ansi_string>
#> [1] MwheD cAyE 123