Added URL stripping

This commit is contained in:
tastytea 2018-05-11 02:36:49 +02:00
parent db592a67ad
commit b5d75af9fb
Signed by: tastytea
GPG Key ID: 59346E0EA35C67E5
4 changed files with 28 additions and 2 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7)
project (expandurl-mastodon
VERSION 0.0.0
VERSION 0.0.2
LANGUAGES CXX
)

View File

@ -21,6 +21,24 @@
using std::string;
/*!
* @brief Expands shortened URLs
*
* @param url URL to expand
*
* @return Expanded URL
*/
const string expand(const string &url);
/*!
* @brief Filters out tracking stuff
*
* Currently remoces all arguments beginning with `utm_`
*
* @param url URL to filter
*
* @return Filtered URL
*/
const string strip(const string &url);
#endif // EXPANDURL_MASTODON_HPP

View File

@ -26,7 +26,8 @@ int main(int argc, char *argv[])
{
curlpp::initialize();
cout << expand(argv[1]) << '\n';
// cout << expand(argv[1]) << '\n';
cout << strip(argv[1]) << '\n';
curlpp::Cleanup();

View File

@ -16,6 +16,7 @@
#include <iostream>
#include <string>
#include <regex>
#include <curlpp/cURLpp.hpp>
#include <curlpp/Options.hpp>
#include <curlpp/Infos.hpp>
@ -52,3 +53,9 @@ const string expand(const string &url)
return curlpp::infos::EffectiveUrl::get(request);
}
const string strip(const string &url)
{
const std::regex re("[\\?&]utm_[^&]+");
return std::regex_replace(url, re, "");
}