diff --git a/include/export/adoc.hpp b/include/export/adoc.hpp index e6f5c13..bd0514c 100644 --- a/include/export/adoc.hpp +++ b/include/export/adoc.hpp @@ -14,8 +14,8 @@ * along with this program. If not, see . */ -#ifndef REMWHAREAD_ADOC_HPP -#define REMWHAREAD_ADOC_HPP +#ifndef REMWHAREAD_EXPORT_ADOC_HPP +#define REMWHAREAD_EXPORT_ADOC_HPP #include #include @@ -48,27 +48,27 @@ namespace Export using replacemap = const std::map; //! Replace strings in text. - const string replace(string text, const replacemap &replacements) const; + string replace(string text, const replacemap &replacements) const; //! Replaces characters in tags that asciidoctor doesn't like. - const string replace_in_tag(const string &text) const; + string replace_in_tag(const string &text) const; //! Replaces characters in title that asciidoctor doesn't like. - const string replace_in_title(const string &text) const; + string replace_in_title(const string &text) const; //! Replaces characters in URI that asciidoctor doesn't like. - const string replace_in_uri(const string &text) const; + string replace_in_uri(const string &text) const; //! Print things sorted by tag. void print_tags(const tagmap &tags) const; //! Get ISO-8601 day from Database::entry. - const string get_day(const Database::entry &entry) const; + string get_day(const Database::entry &entry) const; //! Get ISO-8601 time from Database::entry. - const string get_time(const Database::entry &entry) const; + string get_time(const Database::entry &entry) const; }; -} -} +} // namespace Export +} // namespace remwharead -#endif // REMWHAREAD_ADOC_HPP +#endif // REMWHAREAD_EXPORT_ADOC_HPP diff --git a/include/export/bookmarks.hpp b/include/export/bookmarks.hpp index 2961e22..805b51f 100644 --- a/include/export/bookmarks.hpp +++ b/include/export/bookmarks.hpp @@ -14,8 +14,8 @@ * along with this program. If not, see . */ -#ifndef REMWHAREAD_BOOKMARKS_HPP -#define REMWHAREAD_BOOKMARKS_HPP +#ifndef REMWHAREAD_EXPORT_BOOKMARKS_HPP +#define REMWHAREAD_EXPORT_BOOKMARKS_HPP #include "export.hpp" @@ -34,9 +34,10 @@ namespace Export { public: using ExportBase::ExportBase; - virtual void print() const override; - }; -} -} -#endif // REMWHAREAD_BOOKMARKS_HPP + void print() const override; + }; +} // namespace Export +} // namespace remwharead + +#endif // REMWHAREAD_EXPORT_BOOKMARKS_HPP diff --git a/include/export/csv.hpp b/include/export/csv.hpp index f4090d5..06f0f05 100644 --- a/include/export/csv.hpp +++ b/include/export/csv.hpp @@ -14,8 +14,8 @@ * along with this program. If not, see . */ -#ifndef REMWHAREAD_CSV_HPP -#define REMWHAREAD_CSV_HPP +#ifndef REMWHAREAD_EXPORT_CSV_HPP +#define REMWHAREAD_EXPORT_CSV_HPP #include #include "export.hpp" @@ -38,13 +38,13 @@ namespace Export public: using ExportBase::ExportBase; - virtual void print() const override; + void print() const override; private: //! replaces " with "". - const string quote(string field) const; + string quote(string field) const; }; -} -} +} // namespace Export +} // namespace remwharead -#endif // REMWHAREAD_CSV_HPP +#endif // REMWHAREAD_EXPORT_CSV_HPP diff --git a/include/export/export.hpp b/include/export/export.hpp index 0861cdb..8dba88f 100644 --- a/include/export/export.hpp +++ b/include/export/export.hpp @@ -14,21 +14,20 @@ * along with this program. If not, see . */ -#ifndef REMWHAREAD_EXPORT_HPP -#define REMWHAREAD_EXPORT_HPP +#ifndef REMWHAREAD_EXPORT_EXPORT_HPP +#define REMWHAREAD_EXPORT_EXPORT_HPP #include #include #include "sqlite.hpp" -using std::list; -using std::ostream; -using std::cout; - namespace remwharead { namespace Export { + using std::list; + using std::ostream; + using std::cout; /*! * @brief Base class for exports. * @@ -64,10 +63,9 @@ namespace Export * * @return Sorted list of Database::entry. */ - const list - sort_entries(list entries) const; + list sort_entries(list entries) const; }; -} -} +} // namespace Export +} // namespace remwharead -#endif // REMWHAREAD_EXPORT_HPP +#endif // REMWHAREAD_EXPORT_EXPORT_HPP diff --git a/include/export/json.hpp b/include/export/json.hpp index 40b8e88..44bcfd2 100644 --- a/include/export/json.hpp +++ b/include/export/json.hpp @@ -14,8 +14,8 @@ * along with this program. If not, see . */ -#ifndef REMWHAREAD_JSON_HPP -#define REMWHAREAD_JSON_HPP +#ifndef REMWHAREAD_EXPORT_JSON_HPP +#define REMWHAREAD_EXPORT_JSON_HPP #include #include "export.hpp" @@ -38,9 +38,9 @@ namespace Export public: using ExportBase::ExportBase; - virtual void print() const override; + void print() const override; }; -} -} +} // namespace Export +} // namespace remwharead -#endif // REMWHAREAD_JSON_HPP +#endif // REMWHAREAD_EXPORT_JSON_HPP diff --git a/include/export/rss.hpp b/include/export/rss.hpp index 4840f03..7e5c251 100644 --- a/include/export/rss.hpp +++ b/include/export/rss.hpp @@ -14,8 +14,8 @@ * along with this program. If not, see . */ -#ifndef REMWHAREAD_RSS_HPP -#define REMWHAREAD_RSS_HPP +#ifndef REMWHAREAD_EXPORT_RSS_HPP +#define REMWHAREAD_EXPORT_RSS_HPP #include #include "export.hpp" @@ -38,9 +38,9 @@ namespace Export public: using ExportBase::ExportBase; - virtual void print() const override; + void print() const override; }; -} -} +} // namespace Export +} // namespace remwharead -#endif // REMWHAREAD_RSS_HPP +#endif // REMWHAREAD_EXPORT_RSS_HPP diff --git a/include/export/simple.hpp b/include/export/simple.hpp index 939683c..adac188 100644 --- a/include/export/simple.hpp +++ b/include/export/simple.hpp @@ -14,8 +14,8 @@ * along with this program. If not, see . */ -#ifndef REMWHAREAD_SIMPLE_HPP -#define REMWHAREAD_SIMPLE_HPP +#ifndef REMWHAREAD_EXPORT_SIMPLE_HPP +#define REMWHAREAD_EXPORT_SIMPLE_HPP #include "export.hpp" @@ -34,9 +34,9 @@ namespace Export { public: using ExportBase::ExportBase; - virtual void print() const override; + void print() const override; }; -} -} +} // namespace Export +} // namespace remwharead -#endif // REMWHAREAD_SIMPLE_HPP +#endif // REMWHAREAD_EXPORT_SIMPLE_HPP diff --git a/include/search.hpp b/include/search.hpp index d49d835..6050508 100644 --- a/include/search.hpp +++ b/include/search.hpp @@ -43,7 +43,7 @@ namespace remwharead * * @since 0.7.0 */ - explicit Search(const list &entries); + explicit Search(list entries); /*! * @brief %Search in tags of database entries. @@ -57,8 +57,8 @@ namespace remwharead * * @since 0.7.0 */ - const list search_tags(string expression, - const bool is_re) const; + list search_tags(const string &expression, bool is_re) + const; /*! * @brief %Search in full text of database entries. @@ -72,8 +72,8 @@ namespace remwharead * * @since 0.7.0 */ - const list search_all(string expression, - const bool is_re) const; + list search_all(const string &expression, bool is_re) + const; /*! * @brief Spawn threads of search_all(), if it seems sensible. @@ -88,9 +88,9 @@ namespace remwharead * * @since 0.7.2 */ - // TODO: Think of something more elegant. - const list search_all_threaded(string expression, - const bool is_re) const; + // TODO(tastytea): Think of something more elegant. + list search_all_threaded(const string &expression, + bool is_re) const; private: const list _entries; @@ -106,15 +106,15 @@ namespace remwharead * * @since 0.7.0 */ - const vector> parse_expression(string expression) const; + vector> parse_expression(const string &expression) const; /*! * @brief Convert str to lowercase. Works with unicode. * * @since 0.7.0 */ - inline const string to_lowercase(const string &str) const; + inline string to_lowercase(const string &str) const; }; -} +} // namespace remwharead #endif // REMWHAREAD_SEARCH_HPP diff --git a/include/sqlite.hpp b/include/sqlite.hpp index f33ba37..b9da095 100644 --- a/include/sqlite.hpp +++ b/include/sqlite.hpp @@ -52,7 +52,7 @@ namespace remwharead * * @headerfile sqlite.hpp remwharead/sqlite.hpp */ - typedef struct entry + using entry = struct entry { string uri; string archive_uri; @@ -75,8 +75,8 @@ namespace remwharead * * @since 0.6.0 */ - const string fulltext_oneline() const; - } entry; + string fulltext_oneline() const; + }; /*! * @brief Connects to the database and creates it if necessary. @@ -90,7 +90,7 @@ namespace remwharead * * @since 0.6.0 */ - operator bool() const; + explicit operator bool() const; /*! * @brief Store a Database::entry in the database. @@ -104,9 +104,8 @@ namespace remwharead * * @since 0.6.0 */ - const list retrieve( - const time_point &start = time_point(), - const time_point &end = system_clock::now()) const; + list retrieve(const time_point &start = time_point(), + const time_point &end = system_clock::now()) const; private: fs::path _dbpath; @@ -115,6 +114,6 @@ namespace remwharead }; using DB = Database; -} +} // namespace remwharead #endif // REMWHAREAD_SQLITE_HPP diff --git a/include/time.hpp b/include/time.hpp index 4e52d96..7614b44 100644 --- a/include/time.hpp +++ b/include/time.hpp @@ -36,8 +36,7 @@ namespace remwharead * @param strtime Time string in ISO 8601 or SQLite format. * @param sqlite Is the string in SQLite format? */ - const time_point string_to_timepoint(const string &strtime, - bool sqlite = false); + time_point string_to_timepoint(const string &strtime, bool sqlite = false); /*! * @brief Convert time_point to ISO 8601 or SQLite time-string. @@ -47,7 +46,7 @@ namespace remwharead * @param time_point The std::chrono::system_clock::time_point. * @param sqlite Is the string in SQLite format? */ - const string timepoint_to_string(const time_point &tp, bool sqlite = false); -} + string timepoint_to_string(const time_point &tp, bool sqlite = false); +} // namespace remwharead #endif // REMWHAREAD_TIME_HPP diff --git a/include/types.hpp b/include/types.hpp index a03a1c1..ffdcd19 100644 --- a/include/types.hpp +++ b/include/types.hpp @@ -38,6 +38,6 @@ namespace remwharead json, rss }; -} +} // namespace remwharead #endif // REMWHAREAD_TYPES_HPP diff --git a/include/uri.hpp b/include/uri.hpp index c2df27e..f438ae9 100644 --- a/include/uri.hpp +++ b/include/uri.hpp @@ -32,7 +32,7 @@ namespace remwharead * * @headerfile uri.hpp remwharead/uri.hpp */ - typedef struct html_extract + using html_extract = struct html_extract { bool successful = false; string error; @@ -40,8 +40,8 @@ namespace remwharead string description; string fulltext; - operator bool(); - } html_extract; + explicit operator bool(); + }; /*! * @brief The result of the call to the archive service. @@ -52,14 +52,14 @@ namespace remwharead * * @headerfile uri.hpp remwharead/uri.hpp */ - typedef struct archive_answer + using archive_answer = struct archive_answer { bool successful = false; string error; string uri; - operator bool(); - } archive_answer; + explicit operator bool(); + }; /*! * @brief Download, archive and process an %URI. @@ -79,22 +79,27 @@ namespace remwharead * * @since 0.6.0 */ - explicit URI(const string &uri); + explicit URI(string uri); virtual ~URI(); + URI(const URI &other) = default; + URI &operator=(const URI &other) = default; + URI(URI &&other) = default; + URI &operator=(URI &&other) = default; + /*! * @brief Download %URI and extract title, description and full text. * * @since 0.6.0 */ - const html_extract get(); + html_extract get(); /*! * @brief Save %URI in archive and return archive-URI. * * @since 0.6.0 */ - const archive_answer archive(); + archive_answer archive(); protected: string _uri; @@ -104,29 +109,28 @@ namespace remwharead * * @since 0.6.0 */ - const string make_request(const string &uri, - bool archive = false) const; + string make_request(const string &uri, bool archive = false) const; /*! * @brief Extract the title from an HTML page. * * @since 0.6.0 */ - const string extract_title(const string &html); + string extract_title(const string &html); /*! * @brief Extract the description from an HTML page. * * @since 0.6.0 */ - const string extract_description(const string &html); + string extract_description(const string &html); /*! * @brief Removes HTML tags and superflous spaces from an HTML page. * * @since 0.6.0 */ - const string strip_html(const string &html); + string strip_html(const string &html); /*! * @brief Remove HTML tags. @@ -136,23 +140,29 @@ namespace remwharead * * @since 0.6.0 */ - const string remove_html_tags(const string &html, - const string &tag = ""); + string remove_html_tags(const string &html, const string &tag = ""); /*! * @brief Convert HTML entities to UTF-8. * * @since 0.6.0 */ - const string unescape_html(string html); + string unescape_html(string html); /*! * @brief Replace newlines with spaces. * * @since 0.6.0 */ - const string remove_newlines(string text); + string remove_newlines(string text); + + /*! + * @brief Set proxy server. + * + * @since 0.8.5 + */ + void set_proxy(); }; -} +} // namespace remwharead #endif // REMWHAREAD_URI_HPP diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9c393ac..20c8898 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,3 +1,3 @@ # Write version in header configure_file("version.hpp.in" - "${PROJECT_BINARY_DIR}/version.hpp") + "${CMAKE_CURRENT_BINARY_DIR}/version.hpp") diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index 7694040..88fe5a3 100644 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -10,7 +10,7 @@ set_target_properties(${PROJECT_NAME}-cli PROPERTIES OUTPUT_NAME ${PROJECT_NAME}) target_include_directories(${PROJECT_NAME}-cli - PRIVATE "${PROJECT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") + PRIVATE "${PROJECT_BINARY_DIR}/src" "${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(${PROJECT_NAME}-cli PRIVATE ${PROJECT_NAME}) diff --git a/src/cli/main.cpp b/src/cli/main.cpp index 1103b9f..0306a57 100644 --- a/src/cli/main.cpp +++ b/src/cli/main.cpp @@ -33,6 +33,7 @@ #include "search.hpp" using namespace remwharead; +using namespace remwharead_cli; using std::cerr; using std::endl; using std::string; @@ -58,7 +59,7 @@ int App::main(const std::vector &args) { return 1; } - if (args.size() > 0) + if (!args.empty()) { _uri = args[0]; } diff --git a/src/cli/parse_options.cpp b/src/cli/parse_options.cpp index a708485..9a4163b 100644 --- a/src/cli/parse_options.cpp +++ b/src/cli/parse_options.cpp @@ -20,6 +20,7 @@ #include "version.hpp" #include "remwharead_cli.hpp" +using namespace remwharead_cli; using std::cout; using std::cerr; using std::endl; @@ -31,8 +32,6 @@ App::App() : _help_requested(false) , _version_requested(false) , _argument_error(false) - , _uri() - , _tags() , _format(export_format::undefined) , _timespan({ time_point(), system_clock::now() }) , _archive(true) diff --git a/src/cli/remwharead_cli.hpp b/src/cli/remwharead_cli.hpp index 44db3a9..21533c0 100644 --- a/src/cli/remwharead_cli.hpp +++ b/src/cli/remwharead_cli.hpp @@ -26,40 +26,43 @@ #include "types.hpp" #include "time.hpp" -using namespace remwharead; -using std::string; -using std::vector; -using std::array; -using std::chrono::system_clock; -using time_point = system_clock::time_point; -using Poco::Util::OptionSet; - -class App : public Poco::Util::Application +namespace remwharead_cli { -public: - App(); + using namespace remwharead; + using std::string; + using std::vector; + using std::array; + using std::chrono::system_clock; + using time_point = system_clock::time_point; + using Poco::Util::OptionSet; -protected: - void defineOptions(OptionSet& options); - void handle_info(const std::string &name, const std::string &); - void handle_options(const std::string &name, const std::string &value); - void print_help(); - void print_version(); - int main(const std::vector &args); + class App : public Poco::Util::Application + { + public: + App(); -private: - bool _help_requested; - bool _version_requested; - bool _argument_error; - string _uri; - vector _tags; - export_format _format; - string _file; - array _timespan; - string _search_tags; - string _search_all; - bool _archive; - bool _regex; -}; + protected: + void defineOptions(OptionSet& options) override; + void handle_info(const std::string &name, const std::string &); + void handle_options(const std::string &name, const std::string &value); + void print_help(); + void print_version(); + int main(const std::vector &args) override; + + private: + bool _help_requested; + bool _version_requested; + bool _argument_error; + string _uri; + vector _tags; + export_format _format; + string _file; + array _timespan; + string _search_tags; + string _search_all; + bool _archive; + bool _regex; + }; +} // namespace remwharead_cli #endif // REMWHAREAD_PARSE_OPTIONS_HPP diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 94af7f6..3c1ed0f 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -18,7 +18,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES target_include_directories(${PROJECT_NAME} PRIVATE - "$" # version.hpp + "$" # version.hpp PUBLIC "$" "$") @@ -54,4 +54,3 @@ install(TARGETS ${PROJECT_NAME} EXPORT "${PROJECT_NAME}Targets" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") - diff --git a/src/lib/export/adoc.cpp b/src/lib/export/adoc.cpp index 51abfff..927cf49 100644 --- a/src/lib/export/adoc.cpp +++ b/src/lib/export/adoc.cpp @@ -35,9 +35,9 @@ namespace remwharead try { _out << "= Visited things\n" - << ":Author: remwharead " << global::version << endl + << ":Author: remwharead " << global::version << "\n" << ":Date: " - << timepoint_to_string(system_clock::now()) << endl + << timepoint_to_string(system_clock::now()) << "\n" << ":TOC: right\n" << ":TOCLevels: 2\n" << ":!webfonts:\n\n"; @@ -122,8 +122,8 @@ namespace remwharead } } - const string Export::AsciiDoc::replace(string text, - const replacemap &replacements) const + string Export::AsciiDoc::replace(string text, + const replacemap &replacements) const { for (const std::pair &sr : replacements) { @@ -136,9 +136,9 @@ namespace remwharead } return text; } - const string Export::AsciiDoc::replace_in_tag(const string &text) const + string Export::AsciiDoc::replace_in_tag(const string &text) const { - // TODO: Find a better solution. + // TODO(tastytea): Find a better solution. const replacemap replacements = { { " ", "-" }, { "ยง", "-" }, @@ -164,13 +164,13 @@ namespace remwharead return replace(text, replacements); } - const string Export::AsciiDoc::replace_in_title(const string &text) const + string Export::AsciiDoc::replace_in_title(const string &text) const { // [ is implicitly escaped if the corresponding ] is. return replace(text, {{ "]", "\\]" }}); } - const string Export::AsciiDoc::replace_in_uri(const string &text) const + string Export::AsciiDoc::replace_in_uri(const string &text) const { return replace(text, { @@ -191,17 +191,14 @@ namespace remwharead { // Sort by number of occurrences if they are different. return a.second.size() > b.second.size(); } - else - { // Sort by tag names otherwise. - const std::locale loc; - const std::collate &coll = - std::use_facet>(loc); - return ( - coll.compare( - a.first.data(), a.first.data() + a.first.length(), - b.first.data(), b.first.data() + b.first.length()) - == -1); - } + + // Sort by tag names otherwise. + const std::locale loc; + const auto &coll = std::use_facet>(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