1#' Find the highest index of a substring.
2#'
3#' Like \code{\link{pystr_rfind}} but raises an error if \code{sub} is not found.
4#'
5#' @param str A character vector.
6#' @param sub A character vector.
7#' @param start A numeric vector.
8#' @param end A numeric vector.
9#'
10#' @return A numeric vector.
11#'
12#' @references \url{https://docs.python.org/3/library/stdtypes.html#str.rindex}
13#'
14#' @seealso \code{\link{pystr_index}}
15#'
16#' @examples
17#' pystr_rindex("abcxyzabc", "abc")
18#' pystr_rindex("12121212", "12", 4, 6)
19#' \dontrun{
20#' pystr_rindex("abcxyzabc", "123")
21#' }
22#'
23#' @export
24pystr_rindex <- function(str, sub, start=1, end=nchar(str)) {
25  return(mapply(pystr_rindex_, str, sub, start, end, USE.NAMES=FALSE))
26}
27
28pystr_rindex_ <- function(str, sub, start, end) {
29  idx = pystr_rfind(str, sub, start, end)
30
31  if(any(idx < 0)) {
32    stop("ValueError")
33  }
34
35  return(idx)
36}
37