R/exact.R

Defines functions exact

Documented in exact

#' Exact  
#' 
#' ensure that pattern matches the entire pattern and not any substring
#' 
#' @param pattern string specifying a search pattern. Pattern modifiers can 
#' be used, such as \code{\link{exact}}
#' 
#' @details
#'   Simply wraps a patterns between \code{"^"} and \code{"$"} ensuring that
#'   the regular expression matches the entire pattern.
#' 
#' @note 
#'   This is a poor substitute for being implemented within \code{stringr}. See
#'   \url{https://github.com/hadley/stringr/issues/55}
#' 
#' @references
#'   \url{https://github.com/hadley/stringr/issues/55}
#'   
#' @export   

exact <- function(pattern) {
  if( 
    ! class(pattern) == 'Pattern' ||
    pattern@type == 'regex' 
  ) 
    stop( "Exact only works for regex patterns" )
    
    pattern@.Data <- paste0( "^", pattern, "$" )
    pattern
  }
decisionpatterns/conformist documentation built on Nov. 4, 2019, 10:23 a.m.