From 286a9baa06d4eacdfcc7f351d14cbd6f58dd04b1 Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 14 May 2018 21:44:44 +0200 Subject: [PATCH] mild refactoring --- src/expandurl-mastodon.hpp | 3 ++- src/main.cpp | 17 ----------------- src/masto.cpp | 4 ++++ src/url.cpp | 17 +++++++++++++++++ 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/expandurl-mastodon.hpp b/src/expandurl-mastodon.hpp index d3bf7a7..d5abdc6 100644 --- a/src/expandurl-mastodon.hpp +++ b/src/expandurl-mastodon.hpp @@ -30,6 +30,8 @@ using Mastodon::API; using Mastodon::Easy; void signal_handler(int signum); + + /*! * @brief Extract URLs from HTML * @@ -37,7 +39,6 @@ void signal_handler(int signum); */ const std::vector get_urls(const string &html); - /*! * @brief Expands shortened URLs * diff --git a/src/main.cpp b/src/main.cpp index b6ce172..61b34b6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,23 +47,6 @@ void signal_handler(int signum) } } -const std::vector get_urls(const string &html) -{ - const std::regex re_url("href=\"([^\"]+)\" rel"); - std::smatch match; - string buffer = html; - std::vector v; - - while (std::regex_search(buffer, match, re_url)) - { - string url = Easy::unescape_html(match[1].str()); - v.push_back(strip(expand(url))); - buffer = match.suffix().str(); - } - - return v; -} - int main(int argc, char *argv[]) { signal(SIGINT, signal_handler); diff --git a/src/masto.cpp b/src/masto.cpp index 1478a85..a5aab8e 100644 --- a/src/masto.cpp +++ b/src/masto.cpp @@ -74,6 +74,10 @@ const void Listener::stop() _ptr->cancel_stream(); _thread.join(); } + else + { + cout << "DEBUG: _ptr is false.\n"; + } } std::vector Listener::get_new_messages() diff --git a/src/url.cpp b/src/url.cpp index b5f2f67..b5c0381 100644 --- a/src/url.cpp +++ b/src/url.cpp @@ -27,6 +27,23 @@ using std::cerr; using std::string; namespace curlopts = curlpp::options; +const std::vector get_urls(const string &html) +{ + const std::regex re_url("href=\"([^\"]+)\" rel"); + std::smatch match; + string buffer = html; + std::vector v; + + while (std::regex_search(buffer, match, re_url)) + { + string url = Easy::unescape_html(match[1].str()); + v.push_back(strip(expand(url))); + buffer = match.suffix().str(); + } + + return v; +} + const string expand(const string &url) { curlpp::Easy request;