Browse Source

mild refactoring

tags/0.4.0
tastytea 2 years ago
parent
commit
286a9baa06
Signed by: tastytea GPG Key ID: 59346E0EA35C67E5
4 changed files with 23 additions and 18 deletions
  1. +2
    -1
      src/expandurl-mastodon.hpp
  2. +0
    -17
      src/main.cpp
  3. +4
    -0
      src/masto.cpp
  4. +17
    -0
      src/url.cpp

+ 2
- 1
src/expandurl-mastodon.hpp View File

@@ -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<string> get_urls(const string &html);


/*!
* @brief Expands shortened URLs
*


+ 0
- 17
src/main.cpp View File

@@ -47,23 +47,6 @@ void signal_handler(int signum)
}
}

const std::vector<string> get_urls(const string &html)
{
const std::regex re_url("href=\"([^\"]+)\" rel");
std::smatch match;
string buffer = html;
std::vector<string> 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);


+ 4
- 0
src/masto.cpp View File

@@ -74,6 +74,10 @@ const void Listener::stop()
_ptr->cancel_stream();
_thread.join();
}
else
{
cout << "DEBUG: _ptr is false.\n";
}
}

std::vector<Easy::Notification> Listener::get_new_messages()


+ 17
- 0
src/url.cpp View File

@@ -27,6 +27,23 @@ using std::cerr;
using std::string;
namespace curlopts = curlpp::options;

const std::vector<string> get_urls(const string &html)
{
const std::regex re_url("href=\"([^\"]+)\" rel");
std::smatch match;
string buffer = html;
std::vector<string> 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;


Loading…
Cancel
Save