Skip to content

Commit 11ed268

Browse files
committed
Fix #60
1 parent ac8c8d1 commit 11ed268

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

R/utils-url.R

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ arc_url_parse <- function(url, base_url = NULL) {
3232
# Extract trailing layer number from URL path
3333
layer <- NULL
3434
if (has_arc_url_layer(httr2_url[["path"]])) {
35-
layer <- str_extract(
36-
httr2_url[["path"]],
37-
"(?<=/)([0-9]+(?=/)|[0-9]+$)"
38-
)
35+
layer <- str_extract_layer(httr2_url[["path"]])
3936
}
4037

4138
c(
@@ -57,13 +54,12 @@ has_arc_url_layer <- function(
5754
) {
5855
layer <- layer %||% "[0-9]+"
5956
pattern <- paste0(
60-
"(?<=(",
6157
paste0(services, collapse = "|"),
62-
")/)",
58+
"/",
6359
layer,
6460
"/?$"
6561
)
66-
grepl(pattern, url, perl = TRUE)
62+
grepl(pattern, url)
6763
}
6864

6965
#' Vector of valid ArcGIS service types
@@ -155,3 +151,15 @@ is_url <- function(
155151

156152
grepl(url_pattern, x) & grepl(pattern, x, ...)
157153
}
154+
155+
#' Extract layer number (w/ or w/o trailing slash)
156+
#' @noRd
157+
str_extract_layer <- function(x) {
158+
trailing_txt <- str_extract(
159+
x,
160+
"(?:\\/)([[:digit:]]+)(?:\\/?)$",
161+
perl = FALSE
162+
)
163+
164+
str_extract(trailing_txt, "[[:digit:]]+", perl = FALSE)
165+
}

R/utils.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ check_dots_named <- function(dots, call = rlang::caller_env()) {
4747

4848
#' Extract matching patterns from a string
4949
#' @noRd
50-
str_extract <- function(string, pattern) {
51-
matches <- regexpr(pattern, string, perl = TRUE)
50+
str_extract <- function(string, pattern, perl = TRUE) {
51+
matches <- regexpr(pattern, string, perl = perl)
5252
regmatches(string, matches)
5353
}

0 commit comments

Comments
 (0)