Add escape_url() and unescape_url() to CURLWrapper.

This commit is contained in:
tastytea 2020-01-12 00:49:53 +01:00
parent fd5275f4a3
commit b2f370a727
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 42 additions and 0 deletions

View File

@ -157,6 +157,48 @@ public:
*/
void set_proxy(string_view proxy);
/*!
* @brief URL encodes the given string.
*
* For more information consult [curl_easy_escape(3)]
* (https://curl.haxx.se/libcurl/c/curl_easy_escape.html).
*
* @param url String to escape.
*
* @return The escaped string or {} if it failed.
*
* @since 0.3.0
*/
inline string escape_url(const string_view url) const
{
char *cbuf{curl_easy_escape(_connection, url.data(),
static_cast<int>(url.size()))};
string sbuf{cbuf};
curl_free(cbuf);
return sbuf;
}
/*!
* @brief URL decodes the given string .
*
* For more information consult [curl_easy_unescape(3)]
* (https://curl.haxx.se/libcurl/c/curl_easy_unescape.html).
*
* @param url String to unescape.
*
* @return The unescaped string or {} if it failed.
*
* @since 0.3.0
*/
inline string unescape_url(const string_view url) const
{
char *cbuf{curl_easy_unescape(_connection, url.data(),
static_cast<int>(url.size()), nullptr)};
string sbuf{cbuf};
curl_free(cbuf);
return sbuf;
}
protected:
/*!
* @brief Mutex for #get_buffer a.k.a. _curl_buffer_body.