Merge branch 'develop' into main
continuous-integration/drone/push Build is passing Details

This commit is contained in:
tastytea 2020-01-27 06:55:05 +01:00
commit ee4debb005
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
19 changed files with 96 additions and 59 deletions

View File

@ -5,6 +5,7 @@
Checks: '*,
-cppcoreguidelines-non-private-member-variables-in-classes,
-fuchsia-default-arguments-calls,
-fuchsia-default-arguments-declarations,
-fuchsia-default-arguments,
-llvm-include-order,
-llvm-header-guard,
@ -25,17 +26,18 @@ Checks: '*,
-fuchsia-statically-constructed-objects,
-google-readability-todo,
-modernize-use-trailing-return-type'
CheckOptions: - { key: readability-identifier-naming.ClassCase, value: CamelCase }
CheckOptions: - { key: readability-identifier-naming.ClassCase, value: CamelCase }
# Clashes with constant private member prefix. (const int _var;)
# - { key: readability-identifier-naming.ConstantCase, value: lower_case }
- { key: readability-identifier-naming.EnumCase, value: lower_case }
- { key: readability-identifier-naming.FunctionCase, value: lower_case }
- { key: readability-identifier-naming.MemberCase, value: lower_case }
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
- { key: readability-identifier-naming.ParameterCase, value: lower_case }
- { key: readability-identifier-naming.PrivateMemberCase, value: lower_case }
- { key: readability-identifier-naming.PrivateMemberPrefix, value: _ }
- { key: readability-identifier-naming.StructCase, value: lower_case }
# - { key: readability-identifier-naming.ConstantCase, value: lower_case }
- { key: readability-identifier-naming.EnumCase, value: lower_case }
- { key: readability-identifier-naming.FunctionCase, value: lower_case }
- { key: readability-identifier-naming.MemberCase, value: lower_case }
- { key: readability-identifier-naming.ParameterCase, value: lower_case }
- { key: readability-identifier-naming.PrivateMemberCase, value: lower_case }
- { key: readability-identifier-naming.PrivateMemberPrefix, value: _ }
- { key: readability-identifier-naming.ProtextedMemberCase, value: lower_case }
- { key: readability-identifier-naming.ProtectedMemberPrefix, value: _ }
- { key: readability-identifier-naming.StructCase, value: lower_case }
# Clashes with static private member prefix. (static int _var;)
# - { key: readability-identifier-naming.VariableCase, value: lower_case }
# - { key: readability-identifier-naming.VariableCase, value: lower_case }
...

View File

@ -30,6 +30,8 @@ using std::system;
string read_input();
void send_message(const string &message);
int launch(const string &args);
string decode_args(const string &args);
void replace_in_field(string &field);
string read_input()
{
@ -78,11 +80,44 @@ int launch(const string &args)
return ret;
}
string decode_args(const string &args)
{
constexpr char separator{'\u001F'}; // UNIT SEPARATOR.
if (args[0] != separator) // Extension uses old method.
{
return args;
}
size_t pos{1};
size_t endpos{0};
string newargs;
while ((endpos = args.find(separator, pos)) != string::npos)
{
string field{args.substr(pos, endpos - pos)};
replace_in_field(field);
newargs += " \"" + field + '"';
pos = endpos + 1;
}
return newargs;
}
void replace_in_field(string &field)
{
size_t pos{0};
while ((pos = field.find('"', pos)) != string::npos)
{
field.replace(pos, 1, R"(\")"); // Replace " with \".
pos += 2;
}
}
int main()
{
const string args = read_input();
const int ret = launch(args);
cout << decode_args(args) << std::endl;
const int ret = launch(decode_args(args));
if (ret == 0)
{

View File

@ -47,30 +47,30 @@ private:
//! Replace strings in text.
[[nodiscard]]
string replace(string text, const replacemap &replacements) const;
static string replace(string text, const replacemap &replacements);
//! Replaces characters in tags that asciidoctor doesn't like.
[[nodiscard]]
string replace_in_tag(const string &text) const;
static string replace_in_tag(const string &text);
//! Replaces characters in title that asciidoctor doesn't like.
[[nodiscard]]
string replace_in_title(const string &text) const;
static string replace_in_title(const string &text);
//! Replaces characters in URI that asciidoctor doesn't like.
[[nodiscard]]
string replace_in_uri(const string &text) const;
static string replace_in_uri(const string &text);
//! Print things sorted by tag.
void print_tags(const tagmap &tags) const;
//! Get ISO-8601 day from Database::entry.
[[nodiscard]]
string get_day(const Database::entry &entry) const;
static string get_day(const Database::entry &entry);
//! Get ISO-8601 time from Database::entry.
[[nodiscard]]
string get_time(const Database::entry &entry) const;
static string get_time(const Database::entry &entry);
};
} // namespace remwharead::Export

View File

@ -41,7 +41,7 @@ namespace remwharead::Export
private:
//! replaces " with "".
[[nodiscard]]
string quote(string field) const;
static string quote(string field);
};
} // namespace remwharead::Export

View File

@ -68,7 +68,7 @@ protected:
* @return Sorted list of Database::entry.
*/
[[nodiscard]]
list<Database::entry> sort_entries(list<Database::entry> entries) const;
static list<Database::entry> sort_entries(list<Database::entry> entries);
};
} // namespace remwharead::Export

View File

@ -110,7 +110,7 @@ private:
* @since 0.7.0
*/
[[nodiscard]]
vector<vector<string>> parse_expression(const string &expression) const;
static vector<vector<string>> parse_expression(const string &expression);
/*!
* @brief Convert str to lowercase. Works with unicode.
@ -118,7 +118,7 @@ private:
* @since 0.7.0
*/
[[nodiscard]]
inline string to_lowercase(const string &str) const;
static inline string to_lowercase(const string &str);
};
} // namespace remwharead

View File

@ -132,7 +132,7 @@ private:
bool _connected;
[[nodiscard]]
fs::path get_data_home() const;
static fs::path get_data_home();
};
} // namespace remwharead

View File

@ -151,7 +151,7 @@ protected:
* @since 0.6.0
*/
[[nodiscard]]
string remove_html_tags(const string &html, const string &tag = "") const;
static string remove_html_tags(const string &html, const string &tag = "");
/*!
* @brief Convert HTML entities to UTF-8.
@ -159,7 +159,7 @@ protected:
* @since 0.6.0
*/
[[nodiscard]]
string unescape_html(string html) const;
static string unescape_html(string html);
/*!
* @brief Replace newlines with spaces.
@ -167,14 +167,14 @@ protected:
* @since 0.6.0
*/
[[nodiscard]]
string remove_newlines(string text) const;
static string remove_newlines(string text);
/*!
* @brief Set proxy server.
*
* @since 0.8.5
*/
void set_proxy();
static void set_proxy();
/*!
* @brief Limits text to N characters, cuts at space.
@ -182,7 +182,7 @@ protected:
* @since 0.8.5
*/
[[nodiscard]]
string cut_text(const string &text, uint16_t n_chars) const;
static string cut_text(const string &text, uint16_t n_chars);
/*!
* @brief Converts string to UTF-8.
@ -204,6 +204,7 @@ protected:
*
* @since 0.9.2
*/
[[nodiscard]]
bool is_html() const;
};
} // namespace remwharead

View File

@ -32,12 +32,12 @@ using Poco::Util::OptionCallback;
using Poco::Util::HelpFormatter;
App::App()
: _exit_requested(false)
, _argument_error(false)
, _format(export_format::undefined)
, _timespan({ time_point(), system_clock::now() })
, _archive(true)
, _regex(false)
: _exit_requested{false}
, _argument_error{false}
, _format{export_format::undefined}
, _timespan{{time_point(), system_clock::now()}}
, _archive{true}
, _regex{false}
{}
void App::defineOptions(OptionSet& options)
@ -237,7 +237,7 @@ void App::print_help(const string &option)
void App::print_version()
{
cout << "remwharead " << global::version << endl <<
cout << "remwharead " << remwharead::version << endl <<
"Copyright (C) 2019 tastytea <tastytea@tastytea.de>\n"
"License GPLv3: GNU GPL version 3 "
"<https://www.gnu.org/licenses/gpl-3.0.html>.\n"

View File

@ -44,7 +44,7 @@ protected:
void defineOptions(OptionSet& options) override;
void handle_options(const string &name, const string &value);
void print_help(const string &option);
void print_version();
static void print_version();
int main(const std::vector<string> &args) override;
private:

View File

@ -36,7 +36,7 @@ void Export::AsciiDoc::print() const
try
{
_out << "= Visited things\n"
<< ":Author: remwharead " << global::version << "\n"
<< ":Author: remwharead " << version << "\n"
<< ":Date: "
<< timepoint_to_string(system_clock::now()) << "\n"
<< ":TOC: right\n"
@ -124,7 +124,6 @@ void Export::AsciiDoc::print() const
}
string Export::AsciiDoc::replace(string text, const replacemap &replacements)
const
{
for (const std::pair<const string, const string> &sr : replacements)
{
@ -137,7 +136,7 @@ string Export::AsciiDoc::replace(string text, const replacemap &replacements)
}
return text;
}
string Export::AsciiDoc::replace_in_tag(const string &text) const
string Export::AsciiDoc::replace_in_tag(const string &text)
{
// TODO(tastytea): Find a better solution.
const replacemap replacements =
@ -165,13 +164,13 @@ string Export::AsciiDoc::replace_in_tag(const string &text) const
return replace(text, replacements);
}
string Export::AsciiDoc::replace_in_title(const string &text) const
string Export::AsciiDoc::replace_in_title(const string &text)
{
// [ is implicitly escaped if the corresponding ] is.
return replace(text, {{ "]", "\\]" }});
}
string Export::AsciiDoc::replace_in_uri(const string &text) const
string Export::AsciiDoc::replace_in_uri(const string &text)
{
string out;
Poco::URI::encode(text, "+", out);
@ -196,7 +195,9 @@ void Export::AsciiDoc::print_tags(const tagmap &tags) const
const std::locale loc;
const auto &coll = std::use_facet<std::collate<char>>(loc);
return (coll.compare(
// NOLINTNEXTLINE pointer arithmetic
&a.first[0], &a.first[0] + a.first.size(),
// NOLINTNEXTLINE pointer arithmetic
&b.first[0], &b.first[0] + b.first.size()) == -1);
};
std::sort(sortedtags.begin(), sortedtags.end(), compare_tags);
@ -235,13 +236,13 @@ void Export::AsciiDoc::print_tags(const tagmap &tags) const
_out << endl;
}
string Export::AsciiDoc::get_day(const Database::entry &entry) const
string Export::AsciiDoc::get_day(const Database::entry &entry)
{
const string datetime = timepoint_to_string(entry.datetime);
return datetime.substr(0, datetime.find('T'));
}
string Export::AsciiDoc::get_time(const Database::entry &entry) const
string Export::AsciiDoc::get_time(const Database::entry &entry)
{
const string datetime = timepoint_to_string(entry.datetime);
return datetime.substr(datetime.find('T') + 1);

View File

@ -45,7 +45,7 @@ void Export::CSV::print() const
}
}
string Export::CSV::quote(string field) const
string Export::CSV::quote(string field)
{
size_t pos = 0;
while ((pos = field.find('"', pos)) != std::string::npos)

View File

@ -25,7 +25,7 @@ ExportBase::ExportBase(const list<Database::entry> &entries, ostream &out)
{}
list<Database::entry>
ExportBase::sort_entries(list<Database::entry> entries) const
ExportBase::sort_entries(list<Database::entry> entries)
{
entries.sort([](const auto &a, const auto &b)
{

View File

@ -66,7 +66,7 @@ void Export::RSS::print() const
writer.endElement("", "", "description");
writer.startElement("", "", "generator");
writer.characters(string("remwharead ") + global::version);
writer.characters(string("remwharead ") + version);
writer.endElement("", "", "generator");
const string now = DateTimeFormatter::format(DateTime(),

View File

@ -37,7 +37,7 @@ Search::Search(list<Database::entry> entries)
:_entries(move(entries))
{}
vector<vector<string>> Search::parse_expression(const string &expression) const
vector<vector<string>> Search::parse_expression(const string &expression)
{
vector<vector<string>> searchlist;
const RegEx re_or("(.+?) (OR|\\|\\|) ");
@ -78,7 +78,7 @@ vector<vector<string>> Search::parse_expression(const string &expression) const
return searchlist;
}
string Search::to_lowercase(const string &str) const
string Search::to_lowercase(const string &str)
{
return Poco::UTF8::toLower(str);
}

View File

@ -33,7 +33,7 @@ using Poco::Data::Statement;
using Poco::Environment;
Database::Database()
: _connected(false)
: _connected{false}
{
try
{
@ -182,7 +182,7 @@ string Database::tags_to_string(const vector<string> &tags)
return strtags;
}
fs::path Database::get_data_home() const
fs::path Database::get_data_home()
{
fs::path path;

View File

@ -187,7 +187,7 @@ string URI::make_request(const string &uri, bool archive) const
}
HTTPRequest request(method, path, HTTPMessage::HTTP_1_1);
request.set("User-Agent", string("remwharead/") + global::version);
request.set("User-Agent", string("remwharead/") + version);
HTTPResponse response;
@ -286,7 +286,7 @@ string URI::strip_html() const
return unescape_html(out);
}
string URI::remove_html_tags(const string &html, const string &tag) const
string URI::remove_html_tags(const string &html, const string &tag)
{
// NOTE: I did this with regex_replace before, but libstdc++ segfaulted.
string out;
@ -324,7 +324,7 @@ string URI::remove_html_tags(const string &html, const string &tag) const
return out;
}
string URI::unescape_html(string html) const
string URI::unescape_html(string html)
{
// Used to convert int to utf-8 char.
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> u8c;
@ -648,7 +648,7 @@ archive_answer URI::archive() const
return { false, "Unknown error.", "" };
}
string URI::remove_newlines(string text) const
string URI::remove_newlines(string text)
{
size_t posn = 0;
while ((posn = text.find('\n', posn)) != std::string::npos)
@ -666,7 +666,7 @@ string URI::remove_newlines(string text) const
return text;
}
string URI::cut_text(const string &text, const uint16_t n_chars) const
string URI::cut_text(const string &text, const uint16_t n_chars)
{
if (text.size() > n_chars)
{

View File

@ -1,9 +1,9 @@
#ifndef VERSION_HPP
#define VERSION_HPP
namespace global
namespace remwharead
{
static constexpr char version[] = "@PROJECT_VERSION@";
}
} // namespace remwharead
#endif // VERSION_HPP

View File

@ -17,7 +17,6 @@
#include <exception>
#include <string>
#include <chrono>
#include <vector>
#include <catch.hpp>
#include "sqlite.hpp"
#include "search.hpp"
@ -25,7 +24,6 @@
using namespace remwharead;
using std::string;
using std::chrono::system_clock;
using std::vector;
SCENARIO ("Searching works correctly")
{