Skip to content

Commit df00095

Browse files
committed
Prototype recycling in str_detect()
1 parent df75001 commit df00095

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

R/detect.r

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,21 @@
4141
#' # Returns TRUE if the pattern do NOT match
4242
#' str_detect(fruit, "^p", negate = TRUE)
4343
str_detect <- function(string, pattern, negate = FALSE) {
44+
args <- str_recycle(string, pattern)
45+
4446
switch(type(pattern),
4547
empty = ,
46-
bound = str_count(string, pattern) > 0 & !negate,
47-
fixed = stri_detect_fixed(string, pattern, negate = negate, opts_fixed = opts(pattern)),
48-
coll = stri_detect_coll(string, pattern, negate = negate, opts_collator = opts(pattern)),
49-
regex = stri_detect_regex(string, pattern, negate = negate, opts_regex = opts(pattern))
48+
bound = str_count(args$string, args$pattern) > 0 & !negate,
49+
fixed = stri_detect_fixed(args$string, args$pattern, negate = negate, opts_fixed = opts(pattern)),
50+
coll = stri_detect_coll(args$string, args$pattern, negate = negate, opts_collator = opts(pattern)),
51+
regex = stri_detect_regex(args$string, args$pattern, negate = negate, opts_regex = opts(pattern))
5052
)
5153
}
5254

55+
str_recycle <- function(string, pattern, replacement = NULL) {
56+
vctrs::vec_recycle_common(string = string, pattern = pattern, replacement = replacement)
57+
}
58+
5359
#' Detect the presence or absence of a pattern at the beginning or end of a
5460
#' string.
5561
#'

0 commit comments

Comments
 (0)