R/escape-string.R

Defines functions escape_string

Documented in escape_string

#' Escape characters in string. Make safe for string operations.
#'
#' @param string A character vector.
#'
#' @return A character vector.
#' @export
#'
#' @examples
#' escape_string("(Unit 8) 23 Woodland Road")
escape_string <- function(string) {
  from <-
    c("\\(", "\\)", "\\+", "\\*", "\\[", "\\]", "\\{", "\\}", "\\?")
  to <-
    c(
      "\\\\(",
      "\\\\)",
      "\\\\+",
      "\\\\*",
      "\\\\[",
      "\\\\]",
      "\\\\{",
      "\\\\}",
      "\\\\?"
    )

  replace_in_string(string, from, to)
}
xavier-gilbert/sabre documentation built on May 7, 2021, 12:40 p.m.