-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added set functions (fix #15) #59
Conversation
Not sure what is going on with username and password url <- "https://user_1:[email protected]:8080/dir/../api?q=1#frag"
adaR::ada_set_password(url, "hunter2")
#> [1] "https://user_1:hunter2"
adaR::ada_set_username(url, "user_2")
#> [1] "https://user_2" |
src/adaR.cpp
Outdated
return Rcpp_ada_get(url_vec, &ada_get_protocol, decode); | ||
} | ||
|
||
// higher-order function for bool Rcpp_ada_set_* | ||
CharacterVector Rcpp_ada_set_bool( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chainsawriot there are two types of set functions: bool/void, so I defined two Rcpp_ada_set_ main functions. Do you think one can unify them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it can be unified by creating a template. Will give it a try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
template <typename T>
CharacterVector Rcpp_ada_set(
const CharacterVector& url_vec,
std::function<T(ada_url, const char*, size_t)> func,
const CharacterVector& subst, bool decode) {
unsigned int n = url_vec.length();
CharacterVector out(n);
for (int i = 0; i < url_vec.length(); i++) {
String s = url_vec[i];
String s2 = subst[i];
std::string_view input(s.get_cstring());
std::string_view replace(s2.get_cstring());
ada_url url = ada_parse(input.data(), input.length());
if (!ada_is_valid(url)) {
out[i] = NA_STRING;
} else {
func(url, replace.data(), replace.length());
out[i] = charsub(ada_get_href(url));
}
ada_free(url);
}
if (decode) {
out = Rcpp_url_decode2(out);
}
return (out);
}
// [[Rcpp::export]]
CharacterVector Rcpp_ada_set_href(const CharacterVector& url_vec,
const CharacterVector& subst, bool decode) {
return Rcpp_ada_set<bool>(url_vec, &ada_set_href, subst, decode);
}
// [[Rcpp::export]]
CharacterVector Rcpp_ada_set_hash(const CharacterVector& url_vec,
const CharacterVector& subst, bool decode) {
return Rcpp_ada_set<void>(url_vec, &ada_set_hash, subst, decode);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, will integrate that later tonight
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chainsawriot does the trick, thank you again. Finally understood the purpose of templates
No description provided.