File tree Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -32,10 +32,7 @@ arc_url_parse <- function(url, base_url = NULL) {
32
32
# Extract trailing layer number from URL path
33
33
layer <- NULL
34
34
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" ]])
39
36
}
40
37
41
38
c(
@@ -57,13 +54,12 @@ has_arc_url_layer <- function(
57
54
) {
58
55
layer <- layer %|| % " [0-9]+"
59
56
pattern <- paste0(
60
- " (?<=(" ,
61
57
paste0(services , collapse = " |" ),
62
- " )/) " ,
58
+ " / " ,
63
59
layer ,
64
60
" /?$"
65
61
)
66
- grepl(pattern , url , perl = TRUE )
62
+ grepl(pattern , url )
67
63
}
68
64
69
65
# ' Vector of valid ArcGIS service types
@@ -155,3 +151,15 @@ is_url <- function(
155
151
156
152
grepl(url_pattern , x ) & grepl(pattern , x , ... )
157
153
}
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
+ }
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ check_dots_named <- function(dots, call = rlang::caller_env()) {
47
47
48
48
# ' Extract matching patterns from a string
49
49
# ' @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 )
52
52
regmatches(string , matches )
53
53
}
You can’t perform that action at this time.
0 commit comments