diff --git a/src/adaR.cpp b/src/adaR.cpp index 4172c74..a63a3d0 100644 --- a/src/adaR.cpp +++ b/src/adaR.cpp @@ -4,9 +4,10 @@ std::string charsub(const ada_string stringi) { const char* res = stringi.data; size_t len = stringi.length; ada_owned_string stringi_new = ada_idna_to_unicode(res, len); - res = stringi_new.data; - len = stringi_new.length; - return std::string(res, 0, len); + std::string_view output(stringi_new.data, stringi_new.length); + std::string output2 = {output.begin(), output.end()}; + ada_free_owned_string(stringi_new); + return output2; } // [[Rcpp::export]] @@ -24,8 +25,8 @@ DataFrame Rcpp_ada_parse(const CharacterVector& input_vec) { CharacterVector hash(n); for (unsigned int i = 0; i < n; i++) { String s = input_vec[i]; - const char* input = s.get_cstring(); - ada_url url = ada_parse(input, std::strlen(input)); + std::string_view input(s.get_cstring()); + ada_url url = ada_parse(input.data(), input.length()); if (ada_is_valid(url)) { href[i] = charsub(ada_get_href(url)); protocol[i] = charsub(ada_get_protocol(url)); @@ -49,6 +50,7 @@ DataFrame Rcpp_ada_parse(const CharacterVector& input_vec) { search[i] = NA_STRING; hash[i] = NA_STRING; } + ada_free(url); } return (DataFrame::create(Named("href") = href, _["protocol"] = protocol, _["username"] = username, _["password"] = password, @@ -63,13 +65,14 @@ LogicalVector Rcpp_ada_has(const CharacterVector& url_vec, std::function