You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

22 lines
565 B

`%na%` <- function(a, b) if (is.na(a)) b else a
#' Native R slugify (with the help of {stringi})
#'
#' @param x string to slugify
#' @param repl what to replace spaces with
#' @param lower lowercase final output?
#' @export
slugify_native <- function(x, repl = "-", lower = TRUE) {
x <- stri_replace_all_fixed(x, names(slugify_charmap), slugify_charmap, vectorize_all = FALSE)
x <- stri_replace_all_regex(x, "[^\\P{P}-]", "")
x <- stri_trim_both(x)
x <- stri_replace_all_regex(x, "[[:space:]]+", repl)
if (lower) (x <- stri_trans_tolower(x))
x
}