From b5d75af9fb59e2225b27caecb71d76c8cb3f10e8 Mon Sep 17 00:00:00 2001 From: tastytea Date: Fri, 11 May 2018 02:36:49 +0200 Subject: [PATCH] Added URL stripping --- CMakeLists.txt | 2 +- src/expandurl-mastodon.hpp | 18 ++++++++++++++++++ src/main.cpp | 3 ++- src/{expand.cpp => url.cpp} | 7 +++++++ 4 files changed, 28 insertions(+), 2 deletions(-) rename src/{expand.cpp => url.cpp} (91%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 37c842e..2fa6f7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project (expandurl-mastodon - VERSION 0.0.0 + VERSION 0.0.2 LANGUAGES CXX ) diff --git a/src/expandurl-mastodon.hpp b/src/expandurl-mastodon.hpp index 5bbeb15..81fd407 100644 --- a/src/expandurl-mastodon.hpp +++ b/src/expandurl-mastodon.hpp @@ -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 diff --git a/src/main.cpp b/src/main.cpp index a4e182b..1411bbb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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(); diff --git a/src/expand.cpp b/src/url.cpp similarity index 91% rename from src/expand.cpp rename to src/url.cpp index d134ef5..5ee986c 100644 --- a/src/expand.cpp +++ b/src/url.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -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, ""); +}