R/strfind_internal.R

Defines functions .strfind_extract_all .strfind_locate_ith .strfind_locate_all

#' @keywords internal
#' @noRd
.strfind_locate_all <- function(x, p, ..., abortcall) {
  if(is.list(p)){
    return(do.call(stringi::stri_locate_all, c(list(str = x), p, list(...))))
  }
  else if(is.character(p)) {
    return(stringi::stri_locate_all_regex(
      str = x, pattern = p, ...
    ))
  }
  else {
    stop(simpleError("`p` must be a character vector or list", call = abortcall))
  }
}

#' @keywords internal
#' @noRd
.strfind_locate_ith <- function(x, p, i, ..., abortcall) {
  if(is.list(p)){
    
    args <- list(str = x, i = i)
    return(do.call(stri_locate_ith, c(args, p, list(...))))
    
  } else if(is.character(p)) {
    
    return(stri_locate_ith_regex(
      str = x, pattern = p, i = i,  ...
    ))
    
  } else {
    stop(simpleError("`p` must be a character vector or list", call = abortcall))
  }
}


#' @keywords internal
#' @noRd
.strfind_extract_all <- function(x, p, ..., abortcall) {
  if(is.list(p)){
    return(do.call(stringi::stri_extract_all, c(list(str = x), p, list(...))))
  }
  else if(is.character(p)) {
    return(stringi::stri_extract_all_regex(
      str = x, pattern = p, ...
    ))
  }
  else {
    stop(simpleError("`p` must be a character vector or list", call = abortcall))
  }
}

Try the tinycodet package in your browser

Any scripts or data that you put into this service are public.

tinycodet documentation built on Sept. 12, 2024, 7:03 a.m.