|
41 | 41 | #' # Returns TRUE if the pattern do NOT match |
42 | 42 | #' str_detect(fruit, "^p", negate = TRUE) |
43 | 43 | str_detect <- function(string, pattern, negate = FALSE) { |
| 44 | + args <- str_recycle(string, pattern) |
| 45 | + |
44 | 46 | switch(type(pattern), |
45 | 47 | 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)) |
50 | 52 | ) |
51 | 53 | } |
52 | 54 |
|
| 55 | +str_recycle <- function(string, pattern, replacement = NULL) { |
| 56 | + vctrs::vec_recycle_common(string = string, pattern = pattern, replacement = replacement) |
| 57 | +} |
| 58 | + |
53 | 59 | #' Detect the presence or absence of a pattern at the beginning or end of a |
54 | 60 | #' string. |
55 | 61 | #' |
|
0 commit comments