Skip to content

Commit

Permalink
Merge pull request #33 from schochastics/url_decode2
Browse files Browse the repository at this point in the history
fix #32
  • Loading branch information
schochastics authored Sep 25, 2023
2 parents 346f86c + b12ffd5 commit 1b45199
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 4 additions & 4 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

20 changes: 10 additions & 10 deletions R/get.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion R/parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
10 changes: 5 additions & 5 deletions man/url_decode.Rd → man/url_decode2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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}
};

Expand Down
6 changes: 3 additions & 3 deletions src/urldecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-urldecode.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit 1b45199

Please sign in to comment.