Skip to content

Commit

Permalink
Merge pull request #746 from DyfanJones/main
Browse files Browse the repository at this point in the history
faster paws_parse_match
  • Loading branch information
DyfanJones authored Feb 10, 2024
2 parents fcd96db + 52ecab6 commit 23390cf
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions paws.common/R/url.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ paws_url_parse <- function(url) {
)
}

paws_parse_match <- function(x, pattern) {
m <- regexec(pattern, x, perl = TRUE)
pieces <- regmatches(x, m)[[1]][-1]
empty <- pieces == ""
pieces <- as.list(pieces)
pieces[empty] <- list(NULL)
return(pieces)
paws_parse_match <- function(char, pattern) {
match_loc <- regexpr(pattern, char, perl = TRUE)
cap_start <- attr(match_loc, "capture.start")
cap_len <- attr(match_loc, "capture.length")
cap_end <- cap_start + cap_len - 1
cap_end[cap_end == -1] <- 0
pieces <- as.list(substring(char, cap_start, cap_end))
pieces[pieces == ""] <- list(NULL)
pieces
}

# Build a URL from a Url object.
Expand Down

0 comments on commit 23390cf

Please sign in to comment.