mild refactoring
This commit is contained in:
parent
cea2f7c295
commit
286a9baa06
|
@ -30,6 +30,8 @@ using Mastodon::API;
|
||||||
using Mastodon::Easy;
|
using Mastodon::Easy;
|
||||||
|
|
||||||
void signal_handler(int signum);
|
void signal_handler(int signum);
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Extract URLs from HTML
|
* @brief Extract URLs from HTML
|
||||||
*
|
*
|
||||||
|
@ -37,7 +39,6 @@ void signal_handler(int signum);
|
||||||
*/
|
*/
|
||||||
const std::vector<string> get_urls(const string &html);
|
const std::vector<string> get_urls(const string &html);
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Expands shortened URLs
|
* @brief Expands shortened URLs
|
||||||
*
|
*
|
||||||
|
|
17
src/main.cpp
17
src/main.cpp
|
@ -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[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
signal(SIGINT, signal_handler);
|
signal(SIGINT, signal_handler);
|
||||||
|
|
|
@ -74,6 +74,10 @@ const void Listener::stop()
|
||||||
_ptr->cancel_stream();
|
_ptr->cancel_stream();
|
||||||
_thread.join();
|
_thread.join();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout << "DEBUG: _ptr is false.\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Easy::Notification> Listener::get_new_messages()
|
std::vector<Easy::Notification> Listener::get_new_messages()
|
||||||
|
|
17
src/url.cpp
17
src/url.cpp
|
@ -27,6 +27,23 @@ using std::cerr;
|
||||||
using std::string;
|
using std::string;
|
||||||
namespace curlopts = curlpp::options;
|
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)
|
const string expand(const string &url)
|
||||||
{
|
{
|
||||||
curlpp::Easy request;
|
curlpp::Easy request;
|
||||||
|
|
Loading…
Reference in New Issue