From b12ffd516521a6e4b825d5f5d5ecf54ccf615a2c Mon Sep 17 00:00:00 2001 From: schochastics Date: Mon, 25 Sep 2023 10:05:14 +0200 Subject: [PATCH] renamed url_decode to url_decode2 --- NAMESPACE | 2 +- R/RcppExports.R | 8 ++++---- R/get.R | 20 ++++++++++---------- R/parse.R | 2 +- man/{url_decode.Rd => url_decode2.Rd} | 10 +++++----- src/RcppExports.cpp | 10 +++++----- src/urldecode.cpp | 6 +++--- tests/testthat/test-urldecode.R | 2 +- 8 files changed, 30 insertions(+), 30 deletions(-) rename man/{url_decode.Rd => url_decode2.Rd} (53%) diff --git a/NAMESPACE b/NAMESPACE index 32d3b7a..755b939 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -20,6 +20,6 @@ export(ada_has_port) export(ada_has_search) export(ada_url_parse) export(public_suffix) -export(url_decode) +export(url_decode2) importFrom(Rcpp,sourceCpp) useDynLib(adaR, .registration = TRUE) diff --git a/R/RcppExports.R b/R/RcppExports.R index 3c31345..8c5613d 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -79,13 +79,13 @@ Rcpp_ada_get_protocol <- function(input_vec, length_vec) { #' Function to percent-decode characters in URLs #' -#' Similar to [utils::URLdecode] +#' Similar to [utils::URLdecode] and [urltools::url_decode()] #' #' @param url a character vector #' @export #' @examples -#' url_decode("Hello%20World") -url_decode <- function(url) { - .Call(`_adaR_url_decode`, url) +#' url_decode2("Hello%20World") +url_decode2 <- function(url) { + .Call(`_adaR_url_decode2`, url) } diff --git a/R/get.R b/R/get.R index 2d826c1..7d7ced2 100644 --- a/R/get.R +++ b/R/get.R @@ -9,7 +9,7 @@ ada_get_href <- function(url, decode = TRUE) { len <- vapply(url, function(x) nchar(x, type = "bytes"), integer(1), USE.NAMES = FALSE) out <- Rcpp_ada_get_href(url, len) if (isTRUE(decode)) { - return(utils::URLdecode(out)) + return(url_decode2(out)) } return(out) } @@ -25,7 +25,7 @@ ada_get_username <- function(url, decode = TRUE) { len <- vapply(url, function(x) nchar(x, type = "bytes"), integer(1), USE.NAMES = FALSE) out <- Rcpp_ada_get_username(url, len) if (isTRUE(decode)) { - return(utils::URLdecode(out)) + return(url_decode2(out)) } return(out) } @@ -42,7 +42,7 @@ ada_get_password <- function(url, decode = TRUE) { len <- vapply(url, function(x) nchar(x, type = "bytes"), integer(1), USE.NAMES = FALSE) out <- Rcpp_ada_get_password(url, len) if (isTRUE(decode)) { - return(utils::URLdecode(out)) + return(url_decode2(out)) } return(out) } @@ -59,7 +59,7 @@ ada_get_port <- function(url, decode = TRUE) { len <- vapply(url, function(x) nchar(x, type = "bytes"), integer(1), USE.NAMES = FALSE) out <- Rcpp_ada_get_port(url, len) if (isTRUE(decode)) { - return(utils::URLdecode(out)) + return(url_decode2(out)) } return(out) } @@ -76,7 +76,7 @@ ada_get_hash <- function(url, decode = TRUE) { len <- vapply(url, function(x) nchar(x, type = "bytes"), integer(1), USE.NAMES = FALSE) out <- Rcpp_ada_get_hash(url, len) if (isTRUE(decode)) { - return(utils::URLdecode(out)) + return(url_decode2(out)) } return(out) } @@ -93,7 +93,7 @@ ada_get_host <- function(url, decode = TRUE) { len <- vapply(url, function(x) nchar(x, type = "bytes"), integer(1), USE.NAMES = FALSE) out <- Rcpp_ada_get_host(url, len) if (isTRUE(decode)) { - return(utils::URLdecode(out)) + return(url_decode2(out)) } return(out) } @@ -110,7 +110,7 @@ ada_get_hostname <- function(url, decode = TRUE) { len <- vapply(url, function(x) nchar(x, type = "bytes"), integer(1), USE.NAMES = FALSE) out <- Rcpp_ada_get_hostname(url, len) if (isTRUE(decode)) { - return(utils::URLdecode(out)) + return(url_decode2(out)) } return(out) } @@ -127,7 +127,7 @@ ada_get_pathname <- function(url, decode = TRUE) { len <- vapply(url, function(x) nchar(x, type = "bytes"), integer(1), USE.NAMES = FALSE) out <- Rcpp_ada_get_pathname(url, len) if (isTRUE(decode)) { - return(utils::URLdecode(out)) + return(url_decode2(out)) } return(out) } @@ -144,7 +144,7 @@ ada_get_search <- function(url, decode = TRUE) { len <- vapply(url, function(x) nchar(x, type = "bytes"), integer(1), USE.NAMES = FALSE) out <- Rcpp_ada_get_search(url, len) if (isTRUE(decode)) { - return(utils::URLdecode(out)) + return(url_decode2(out)) } return(out) } @@ -161,7 +161,7 @@ ada_get_protocol <- function(url, decode = TRUE) { len <- vapply(url, function(x) nchar(x, type = "bytes"), integer(1), USE.NAMES = FALSE) out <- Rcpp_ada_get_protocol(url, len) if (isTRUE(decode)) { - return(utils::URLdecode(out)) + return(url_decode2(out)) } return(out) } diff --git a/R/parse.R b/R/parse.R index bc37054..d86e64d 100644 --- a/R/parse.R +++ b/R/parse.R @@ -27,7 +27,7 @@ ada_url_parse <- function(url, decode = TRUE) { return(character(0)) } non_na_index <- which(!is.na(URL)) - URL[non_na_index] <- url_decode(URL[non_na_index]) + URL[non_na_index] <- url_decode2(URL[non_na_index]) URL[!non_na_index] <- NA_character_ return(URL) } diff --git a/man/url_decode.Rd b/man/url_decode2.Rd similarity index 53% rename from man/url_decode.Rd rename to man/url_decode2.Rd index 230bab1..408d44d 100644 --- a/man/url_decode.Rd +++ b/man/url_decode2.Rd @@ -1,17 +1,17 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/RcppExports.R -\name{url_decode} -\alias{url_decode} +\name{url_decode2} +\alias{url_decode2} \title{Function to percent-decode characters in URLs} \usage{ -url_decode(url) +url_decode2(url) } \arguments{ \item{url}{a character vector} } \description{ -Similar to \link[utils:URLencode]{utils::URLdecode} +Similar to \link[utils:URLencode]{utils::URLdecode} and \code{\link[urltools:encoder]{urltools::url_decode()}} } \examples{ -url_decode("Hello\%20World") +url_decode2("Hello\%20World") } diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 94ffcf4..e70e9da 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -229,14 +229,14 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } -// url_decode -CharacterVector url_decode(CharacterVector url); -RcppExport SEXP _adaR_url_decode(SEXP urlSEXP) { +// url_decode2 +CharacterVector url_decode2(CharacterVector url); +RcppExport SEXP _adaR_url_decode2(SEXP urlSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< CharacterVector >::type url(urlSEXP); - rcpp_result_gen = Rcpp::wrap(url_decode(url)); + rcpp_result_gen = Rcpp::wrap(url_decode2(url)); return rcpp_result_gen; END_RCPP } @@ -261,7 +261,7 @@ static const R_CallMethodDef CallEntries[] = { {"_adaR_Rcpp_ada_get_pathname", (DL_FUNC) &_adaR_Rcpp_ada_get_pathname, 2}, {"_adaR_Rcpp_ada_get_search", (DL_FUNC) &_adaR_Rcpp_ada_get_search, 2}, {"_adaR_Rcpp_ada_get_protocol", (DL_FUNC) &_adaR_Rcpp_ada_get_protocol, 2}, - {"_adaR_url_decode", (DL_FUNC) &_adaR_url_decode, 1}, + {"_adaR_url_decode2", (DL_FUNC) &_adaR_url_decode2, 1}, {NULL, NULL, 0} }; diff --git a/src/urldecode.cpp b/src/urldecode.cpp index c6f5484..005322d 100644 --- a/src/urldecode.cpp +++ b/src/urldecode.cpp @@ -4,14 +4,14 @@ using namespace Rcpp; //' Function to percent-decode characters in URLs //' -//' Similar to [utils::URLdecode] +//' Similar to [utils::URLdecode] and [urltools::url_decode()] //' //' @param url a character vector //' @export //' @examples -//' url_decode("Hello%20World") +//' url_decode2("Hello%20World") // [[Rcpp::export]] -CharacterVector url_decode(CharacterVector url) { +CharacterVector url_decode2(CharacterVector url) { return sapply(url, [](const String& u) { std::string input = u; std::string output; diff --git a/tests/testthat/test-urldecode.R b/tests/testthat/test-urldecode.R index c98b96b..4e94c9e 100644 --- a/tests/testthat/test-urldecode.R +++ b/tests/testthat/test-urldecode.R @@ -16,5 +16,5 @@ test_that("Integration #21", { test_that("cpp implementation is correct", { enc <- "https%3A%2F%2Fwww.google.de%2Fmaps%2F%4047.6647302%2C9.1389738%2C11z%3Fentry%3Dttu" dec <- "https://www.google.de/maps/@47.6647302,9.1389738,11z?entry=ttu" - expect_equal(url_decode(enc), dec) + expect_equal(url_decode2(enc), dec) })