>(loc);
+ return (
+ coll.compare(
+ &a.first[0], &a.first[0] + a.first.size(),
+ &b.first[0], &b.first[0] + b.first.size()) == -1);
};
std::sort(sortedtags.begin(), sortedtags.end(), compare_tags);
@@ -239,15 +236,15 @@ namespace remwharead
_out << endl;
}
- const string Export::AsciiDoc::get_day(const Database::entry &entry) const
+ string Export::AsciiDoc::get_day(const Database::entry &entry) const
{
const string datetime = timepoint_to_string(entry.datetime);
return datetime.substr(0, datetime.find('T'));
}
- const string Export::AsciiDoc::get_time(const Database::entry &entry) const
+ string Export::AsciiDoc::get_time(const Database::entry &entry) const
{
const string datetime = timepoint_to_string(entry.datetime);
return datetime.substr(datetime.find('T') + 1);
}
-}
+} // namespace remwharead
diff --git a/src/lib/export/bookmarks.cpp b/src/lib/export/bookmarks.cpp
index b3dd63f..2f0efc1 100644
--- a/src/lib/export/bookmarks.cpp
+++ b/src/lib/export/bookmarks.cpp
@@ -56,4 +56,4 @@ namespace remwharead
_out << "\n"
<< "
\n";
}
-}
+} // namespace remwharead
diff --git a/src/lib/export/csv.cpp b/src/lib/export/csv.cpp
index 81972ff..b241428 100644
--- a/src/lib/export/csv.cpp
+++ b/src/lib/export/csv.cpp
@@ -26,8 +26,8 @@ namespace remwharead
{
try
{
- _out << "\"URI\",\"Archived URI\",\"Date & time\",\"Tags\","
- << "\"Title\",\"Description\",\"Full text\"\r\n";
+ _out << R"("URI","Archived URI","Date & time","Tags",)"
+ << R"("Title","Description","Full text")" << "\r\n";
for (const Database::entry &entry : _entries)
{
string strtags;
@@ -54,7 +54,7 @@ namespace remwharead
}
}
- const string Export::CSV::quote(string field) const
+ string Export::CSV::quote(string field) const
{
size_t pos = 0;
while ((pos = field.find('"', pos)) != std::string::npos)
@@ -63,4 +63,4 @@ namespace remwharead
}
return field;
}
-}
+} // namespace remwharead
diff --git a/src/lib/export/export.cpp b/src/lib/export/export.cpp
index 5055b88..2904233 100644
--- a/src/lib/export/export.cpp
+++ b/src/lib/export/export.cpp
@@ -26,7 +26,7 @@ namespace Export
, _out(out)
{}
- const list
+ list
ExportBase::sort_entries(list entries) const
{
entries.sort([](const auto &a, const auto &b)
@@ -37,5 +37,5 @@ namespace Export
return entries;
}
-}
-}
+} // namespace Export
+} // namespace remwharead
diff --git a/src/lib/export/json.cpp b/src/lib/export/json.cpp
index 2b9bf07..5a08515 100644
--- a/src/lib/export/json.cpp
+++ b/src/lib/export/json.cpp
@@ -58,4 +58,4 @@ namespace remwharead
cerr << "Error in " << __func__ << ": " << e.what() << endl;
}
}
-}
+} // namespace remwharead
diff --git a/src/lib/export/rss.cpp b/src/lib/export/rss.cpp
index ac82bd8..1427bbb 100644
--- a/src/lib/export/rss.cpp
+++ b/src/lib/export/rss.cpp
@@ -41,7 +41,8 @@ namespace remwharead
try
{
XMLWriter writer(_out, XMLWriter::CANONICAL);
- AttributesImpl attrs_rss, attrs_guid;
+ AttributesImpl attrs_rss;
+ AttributesImpl attrs_guid;
constexpr char timefmt_rfc822[] = "%w, %d %b %Y %H:%M:%S %Z";
attrs_rss.addAttribute("", "", "version", "", "2.0");
@@ -114,7 +115,7 @@ namespace remwharead
string description = entry.description;
if (!description.empty())
{
- description = "" + description + "
";
+ description = "" + description.append("
");
}
if (!entry.tags.empty())
{
@@ -133,7 +134,7 @@ namespace remwharead
{
description += "Archived version: "
""
- + entry.archive_uri + "";
+ + entry.archive_uri + "
";
}
writer.startElement("", "", "description");
writer.characters(description);
@@ -152,4 +153,4 @@ namespace remwharead
cerr << "Error in " << __func__ << ": " << e.what() << endl;
}
}
-}
+} // namespace remwharead
diff --git a/src/lib/export/simple.cpp b/src/lib/export/simple.cpp
index 03c81fa..1ccedf8 100644
--- a/src/lib/export/simple.cpp
+++ b/src/lib/export/simple.cpp
@@ -38,4 +38,4 @@ namespace remwharead
_out << "<" << entry.uri << ">\n";
}
}
-}
+} // namespace remwharead
diff --git a/src/lib/search.cpp b/src/lib/search.cpp
index e620c07..84a1234 100644
--- a/src/lib/search.cpp
+++ b/src/lib/search.cpp
@@ -33,11 +33,11 @@ namespace remwharead
using std::move;
using RegEx = Poco::RegularExpression;
- Search::Search(const list &entries)
- :_entries(entries)
+ Search::Search(list entries)
+ :_entries(move(entries))
{}
- const vector> Search::parse_expression(string expression)
+ vector> Search::parse_expression(const string &expression)
const
{
vector> searchlist;
@@ -59,7 +59,7 @@ namespace remwharead
}
{
- for (string sub : subexpressions)
+ for (const string &sub : subexpressions)
{ // Split each OR-slice at AND.
vector terms;
pos = 0;
@@ -79,13 +79,13 @@ namespace remwharead
return searchlist;
}
- const string Search::to_lowercase(const string &str) const
+ string Search::to_lowercase(const string &str) const
{
return Poco::UTF8::toLower(str);
}
- const list Search::search_tags(string expression,
- const bool is_re) const
+ list Search::search_tags(const string &expression,
+ const bool is_re) const
{
vector> searchlist = parse_expression(expression);
list result;
@@ -108,17 +108,15 @@ namespace remwharead
const RegEx re("^" + tag + "$");
return (re == s);
}
- else
- {
- return (s == tag);
- }
+
+ return (s == tag);
});
if (it == entry.tags.end())
{
matched = false;
}
}
- if (matched == true)
+ if (matched)
{
result.push_back(entry);
}
@@ -128,8 +126,8 @@ namespace remwharead
return result;
}
- const list Search::search_all(string expression,
- const bool is_re) const
+ list Search::search_all(const string &expression,
+ const bool is_re) const
{
vector> searchlist = parse_expression(expression);
list result = search_tags(expression, is_re);
@@ -194,9 +192,7 @@ namespace remwharead
}
}
}
- if (matched_title == true
- || matched_description == true
- || matched_fulltext == true)
+ if (matched_title || matched_description || matched_fulltext)
{
result.push_back(entry);
}
@@ -206,8 +202,8 @@ namespace remwharead
return result;
}
- const list Search::search_all_threaded(
- string expression, const bool is_re) const
+ list Search::search_all_threaded(const string &expression,
+ const bool is_re) const
{
list entries = _entries;
@@ -242,7 +238,9 @@ namespace remwharead
segments.push_back(move(segment));
}
// Move rest of `entries` into `segments`.
- segments.push_back(move(entries));
+ list segment;
+ segment.splice(segment.begin(), entries);
+ segments.push_back(move(segment));
list threads;
for (auto &segment : segments)
@@ -266,5 +264,6 @@ namespace remwharead
}
return entries;
+
}
-}
+} // namespace remwharead
diff --git a/src/lib/sqlite.cpp b/src/lib/sqlite.cpp
index 0a86660..f1046fe 100644
--- a/src/lib/sqlite.cpp
+++ b/src/lib/sqlite.cpp
@@ -70,7 +70,7 @@ namespace remwharead
return (a.datetime == b.datetime);
}
- const string Database::entry::fulltext_oneline() const
+ string Database::entry::fulltext_oneline() const
{
string oneline = fulltext;
size_t pos = 0;
@@ -112,13 +112,14 @@ namespace remwharead
}
}
- const list Database::retrieve(
- const time_point &start, const time_point &end) const
+ list Database::retrieve(const time_point &start,
+ const time_point &end) const
{
try
{
Database::entry entrybuf;
- string datetime, strtags;
+ string datetime;
+ string strtags;
Statement select(*_session);
// bind() copies the value.
@@ -166,4 +167,4 @@ namespace remwharead
return {};
}
-}
+} // namespace remwharead
diff --git a/src/lib/time.cpp b/src/lib/time.cpp
index 7eab9eb..a6dbff1 100644
--- a/src/lib/time.cpp
+++ b/src/lib/time.cpp
@@ -25,7 +25,7 @@ namespace remwharead
{
using std::array;
- const time_point string_to_timepoint(const string &strtime, bool sqlite)
+ time_point string_to_timepoint(const string &strtime, bool sqlite)
{
std::stringstream sstime(strtime);
struct std::tm tm = {};
@@ -42,7 +42,7 @@ namespace remwharead
return system_clock::from_time_t(time);
}
- const string timepoint_to_string(const time_point &tp, bool sqlite)
+ string timepoint_to_string(const time_point &tp, bool sqlite)
{
constexpr std::uint16_t bufsize = 32;
std::time_t time = system_clock::to_time_t(tp);
diff --git a/src/lib/uri.cpp b/src/lib/uri.cpp
index 45020f7..3b80f2c 100644
--- a/src/lib/uri.cpp
+++ b/src/lib/uri.cpp
@@ -21,6 +21,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -42,6 +43,7 @@ namespace remwharead
using std::vector;
using std::cerr;
using std::endl;
+ using std::move;
using Poco::Net::HTTPClientSession;
using Poco::Net::HTTPSClientSession;
using Poco::Net::HTTPRequest;
@@ -61,11 +63,16 @@ namespace remwharead
return successful;
}
- URI::URI(const string &uri)
- :_uri(uri)
+ URI::URI(string uri)
+ :_uri(move(uri))
{
Poco::Net::initializeSSL();
+ set_proxy();
+ }
+
+ void URI::set_proxy()
+ {
try
{
HTTPClientSession::ProxyConfig proxy;
@@ -74,20 +81,23 @@ namespace remwharead
"([^:/]+)(?::([\\d]{1,5}))?/?$");
vector matches;
- if (re_proxy.split(env_proxy, matches) >= 4)
+ if (re_proxy.split(env_proxy, matches) < 4)
{
- proxy.username = matches[1];
- proxy.password = matches[2];
- proxy.host = matches[3];
- if (!matches[4].empty())
+ return;
+ }
+
+ proxy.username = matches[1];
+ proxy.password = matches[2];
+ proxy.host = matches[3];
+ if (!matches[4].empty())
+ {
+ const std::uint32_t &port = std::stoul(matches[4]);
+ if (port > 65535)
{
- const std::uint32_t &port = std::stoul(matches[4]);
- if (port > 65535)
- {
- throw std::invalid_argument("Port number out of range");
- }
- proxy.port = port;
+ throw std::invalid_argument(
+ "Proxy port number out of range");
}
+ proxy.port = port;
}
HTTPClientSession::setGlobalProxyConfig(proxy);
}
@@ -100,10 +110,14 @@ namespace remwharead
{
cerr << "Error: " << e.what() << endl;
}
- catch (const std::exception &)
+ catch (const Poco::NotFoundException &)
{
// No proxy found, no problem.
}
+ catch (const std::exception &e)
+ {
+ cerr << "Unexpected exception: " << e.what() << endl;
+ }
}
URI::~URI()
@@ -111,7 +125,7 @@ namespace remwharead
Poco::Net::uninitializeSSL();
}
- const html_extract URI::get()
+ html_extract URI::get()
{
try
{
@@ -136,7 +150,7 @@ namespace remwharead
return { false, "Unknown error.", "", "", "" };
}
- const string URI::make_request(const string &uri, bool archive) const
+ string URI::make_request(const string &uri, bool archive) const
{
Poco::URI poco_uri(uri);
string method =
@@ -209,7 +223,7 @@ namespace remwharead
}
}
- const string URI::extract_title(const string &html)
+ string URI::extract_title(const string &html)
{
const RegEx re_htmlfile(".*\\.(.?html?|xml|rss)$", RegEx::RE_CASELESS);
if (_uri.substr(0, 4) == "http" || re_htmlfile.match(_uri))
@@ -226,12 +240,12 @@ namespace remwharead
return "";
}
- const string URI::extract_description(const string &html)
+ string URI::extract_description(const string &html)
{
const RegEx re_htmlfile(".*\\.(.?html?|xml|rss)$", RegEx::RE_CASELESS);
if (_uri.substr(0, 4) == "http" || re_htmlfile.match(_uri))
{
- const RegEx re_desc("description\"[^>]+content=\"([^\"]+)",
+ const RegEx re_desc(R"(description"[^>]+content="([^"]+))",
RegEx::RE_CASELESS);
vector matches;
re_desc.split(html, matches);
@@ -244,7 +258,7 @@ namespace remwharead
return "";
}
- const string URI::strip_html(const string &html)
+ string URI::strip_html(const string &html)
{
string out;
@@ -253,7 +267,7 @@ namespace remwharead
out = remove_html_tags(out); // Remove tags.
size_t pos = 0;
- while ((pos = out.find("\r", pos)) != std::string::npos) // Remove CR.
+ while ((pos = out.find('\r', pos)) != std::string::npos) // Remove CR.
{
out.replace(pos, 1, "");
}
@@ -265,7 +279,7 @@ namespace remwharead
return unescape_html(out);
}
- const string URI::remove_html_tags(const string &html, const string &tag)
+ string URI::remove_html_tags(const string &html, const string &tag)
{
// NOTE: I did this with regex_replace before, but libstdc++ segfaulted.
string out;
@@ -303,7 +317,7 @@ namespace remwharead
return out;
}
- const string URI::unescape_html(string html)
+ string URI::unescape_html(string html)
{
// Used to convert int to utf-8 char.
std::wstring_convert, char32_t> u8c;
@@ -603,7 +617,7 @@ namespace remwharead
return html;
}
- const archive_answer URI::archive()
+ archive_answer URI::archive()
{
if (_uri.substr(0, 4) != "http")
{
@@ -628,7 +642,7 @@ namespace remwharead
return { false, "Unknown error.", "" };
}
- const string URI::remove_newlines(string text)
+ string URI::remove_newlines(string text)
{
size_t posn = 0;
while ((posn = text.find('\n', posn)) != std::string::npos)
@@ -645,4 +659,4 @@ namespace remwharead
return text;
}
-}
+} // namespace remwharead