diff --git a/lib/message/mu-fields.hh b/lib/message/mu-fields.hh index 698f0920..876923cc 100644 --- a/lib/message/mu-fields.hh +++ b/lib/message/mu-fields.hh @@ -212,16 +212,15 @@ struct Field { }; // equality -static inline constexpr bool operator==(const Field& f1, const Field& f2) { return f1.id == f2.id; } -static inline constexpr bool operator==(const Field& f1, const Field::Id id) { return f1.id == id; } - +constexpr bool operator==(const Field& f1, const Field& f2) { return f1.id == f2.id; } +constexpr bool operator==(const Field& f1, const Field::Id id) { return f1.id == id; } MU_ENABLE_BITOPS(Field::Flag); /** * Sequence of _all_ message fields */ -static constexpr std::array +inline constexpr std::array Fields = { { { @@ -530,13 +529,13 @@ constexpr Option field_find_if(Pred&& pred) { * * @return the message-field or Nothing */ -static inline +inline Option field_from_shortcut(char shortcut) { return field_find_if([&](auto&& field){ return field.shortcut == shortcut; }); } -static inline +inline Option field_from_name(const std::string& name) { switch(name.length()) { case 0: @@ -595,8 +594,7 @@ bool field_is_combi (const std::string& name); * * @return Field::Id or nullopt */ -static inline -Option field_from_number(size_t id) +constexpr Option field_from_number(size_t id) { if (id >= static_cast(Field::Id::_count_)) return Nothing; diff --git a/lib/message/mu-flags.hh b/lib/message/mu-flags.hh index 6c528b6c..0dc71b8b 100644 --- a/lib/message/mu-flags.hh +++ b/lib/message/mu-flags.hh @@ -112,7 +112,7 @@ struct MessageFlagInfo { /** * Array of all flag information. */ -constexpr std::array AllMessageFlagInfos = {{ +inline constexpr auto AllMessageFlagInfos = std::to_array({ MessageFlagInfo{Flags::Draft, 'D', "draft", MessageFlagCategory::Mailfile, "Draft (in progress)" }, @@ -155,7 +155,7 @@ constexpr std::array AllMessageFlagInfos = {{ MessageFlagInfo{Flags::Calendar, 'c', "calendar", MessageFlagCategory::Content, "Calendar invitation" }, -}}; +}); /** @@ -409,7 +409,7 @@ std::string to_string(Flags flags); * * @return string as a sequence of message-flag shortcuts */ -static inline auto format_as(const Flags& flags) { +inline auto format_as(const Flags& flags) { return to_string(flags); } diff --git a/lib/message/mu-labels.cc b/lib/message/mu-labels.cc index f10f1dbf..02f08b74 100644 --- a/lib/message/mu-labels.cc +++ b/lib/message/mu-labels.cc @@ -106,11 +106,9 @@ Mu::Labels::parse_delta_labels(const std::string& exprs, return Ok(std::move(deltas)); } -struct cmp_delta_label { // can not yet be a λ in C++17 - bool operator()(const DeltaLabel& dl1, const DeltaLabel& dl2) const { - return dl1.second < dl2.second; - } -}; +using cmp_delta_label = decltype([](const DeltaLabel& dl1, const DeltaLabel& dl2) { + return dl1.second < dl2.second; +}); std::pair Mu::Labels::updated_labels(const LabelVec& labels, const DeltaLabelVec& deltas) { diff --git a/lib/message/mu-message-file.cc b/lib/message/mu-message-file.cc index b077c3bb..a01cca65 100644 --- a/lib/message/mu-message-file.cc +++ b/lib/message/mu-message-file.cc @@ -75,7 +75,7 @@ Mu::base_message_dir_file(const std::string& path) constexpr auto newdir{"/new"}; const auto dname{dirname(path)}; - bool is_new{!!g_str_has_suffix(dname.c_str(), newdir)}; + bool is_new{dname.ends_with(newdir)}; std::string mdir{dname.substr(0, dname.size() - 4)}; return Ok(DirFile{std::move(mdir), basename(path), is_new}); @@ -118,9 +118,9 @@ Mu::flags_from_path(const std::string& path) static void test_maildir_from_path() { - std::array, 1> test_cases = {{ + auto test_cases = std::to_array>({ { "/home/foo/Maildir/hello/cur/msg123", "/home/foo/Maildir", "/hello" } - }}; + }); for(auto&& tcase: test_cases) { const auto res{maildir_from_path(std::get<0>(tcase), std::get<1>(tcase))}; @@ -140,10 +140,10 @@ test_base_message_dir_file() const std::string path; DirFile expected; }; - std::array test_cases = {{ + auto test_cases = std::to_array({ { "/home/djcb/Maildir/foo/cur/msg:2,S", { "/home/djcb/Maildir/foo", "msg:2,S", false } } - }}; + }); for(auto&& tcase: test_cases) { const auto res{base_message_dir_file(tcase.path)}; assert_valid_result(res); @@ -156,7 +156,7 @@ test_base_message_dir_file() static void test_flags_from_path() { - std::array, 5> test_cases = {{ + auto test_cases = std::to_array>({ {"/home/foo/Maildir/test/cur/123456:2,FSR", (Flags::Replied | Flags::Seen | Flags::Flagged)}, {"/home/foo/Maildir/test/new/123456", Flags::New}, @@ -166,7 +166,7 @@ test_flags_from_path() {"/home/foo/Maildir/test/cur/123456:2,DTP", (Flags::Draft | Flags::Trashed | Flags::Passed)}, {"/home/foo/Maildir/test/cur/123456:2,S", Flags::Seen} - }}; + }); for (auto&& tcase: test_cases) { auto res{flags_from_path(tcase.first)}; diff --git a/lib/message/mu-message-part.cc b/lib/message/mu-message-part.cc index 4134fb5e..6ec16483 100644 --- a/lib/message/mu-message-part.cc +++ b/lib/message/mu-message-part.cc @@ -224,12 +224,12 @@ MessagePart::looks_like_attachment() const noexcept static void test_cooked_full() { - std::array, 4> cases = {{ + auto cases = std::to_array>({ { "/hello/world/foo", "foo" }, { "foo:/\n/bar", "bar"}, { "Aap Noot Mies", "Aap-Noot-Mies"}, { "..", "-"} - }}; + }); for (auto&& test: cases) assert_equal(cook_full(test.first), test.second); @@ -238,12 +238,12 @@ test_cooked_full() static void test_cooked_minimal() { - std::array, 4> cases = {{ + auto cases = std::to_array>({ { "/hello/world/foo", "foo" }, { "foo:/\n/bar", "bar"}, { "Aap Noot Mies.doc", "Aap Noot Mies.doc"}, { "..", "-"} - }}; + }); for (auto&& test: cases) assert_equal(cook_minimal(test.first), test.second); diff --git a/lib/message/mu-message.cc b/lib/message/mu-message.cc index a0912633..7599ed22 100644 --- a/lib/message/mu-message.cc +++ b/lib/message/mu-message.cc @@ -281,8 +281,8 @@ Message::has_mime_message() const static Priority get_priority(const MimeMessage& mime_msg) { - constexpr std::array, 10> - prio_alist = {{ + constexpr auto prio_alist = + std::to_array>({ {"high", Priority::High}, {"1", Priority::High}, {"2", Priority::High}, @@ -295,7 +295,7 @@ get_priority(const MimeMessage& mime_msg) {"bulk", Priority::Low}, {"4", Priority::Low}, {"5", Priority::Low} - }}; + }); const auto opt_str = mime_msg.header("Precedence") .disjunction(mime_msg.header("X-Priority")) @@ -316,9 +316,9 @@ get_priority(const MimeMessage& mime_msg) static std::vector extract_tags(const MimeMessage& mime_msg) { - constexpr std::array, 3> tag_headers = {{ + constexpr auto tag_headers = std::to_array>({ {"X-Label", ' '}, {"X-Keywords", ','}, {"Keywords", ','} - }}; + }); std::vector tags; seq_for_each(tag_headers, [&](auto&& item) { diff --git a/lib/message/mu-message.hh b/lib/message/mu-message.hh index 065ad5cc..c8f242cb 100644 --- a/lib/message/mu-message.hh +++ b/lib/message/mu-message.hh @@ -512,7 +512,7 @@ private: }; // Message MU_ENABLE_BITOPS(Message::Options); -static inline auto +inline auto format_as(const Message& msg) { return msg.path(); } diff --git a/lib/message/mu-mime-object.hh b/lib/message/mu-mime-object.hh index 6c846a30..74bed074 100644 --- a/lib/message/mu-mime-object.hh +++ b/lib/message/mu-mime-object.hh @@ -449,8 +449,8 @@ private: } }; -constexpr std::array, 11> -AllPubkeyAlgos = {{ +inline constexpr auto +AllPubkeyAlgos = std::to_array>({ { MimeCertificate::PubkeyAlgo::Default, "default"}, { MimeCertificate::PubkeyAlgo::Rsa, "rsa"}, { MimeCertificate::PubkeyAlgo::RsaE, "rsa-encryption-only"}, @@ -462,14 +462,14 @@ AllPubkeyAlgos = {{ { MimeCertificate::PubkeyAlgo::EcDsa, "elliptic-curve+dsa"}, { MimeCertificate::PubkeyAlgo::EcDh, "elliptic-curve+diffie-helman"}, { MimeCertificate::PubkeyAlgo::EdDsa, "elliptic-curve+dsa-2"} - }}; + }); constexpr Option to_string_view_opt(MimeCertificate::PubkeyAlgo algo) { return to_string_view_opt(AllPubkeyAlgos, algo); } -constexpr std::array, 15> -AllDigestAlgos = {{ +inline constexpr auto +AllDigestAlgos = std::to_array>({ { MimeCertificate::DigestAlgo::Default, "default"}, { MimeCertificate::DigestAlgo::Md5, "md5"}, { MimeCertificate::DigestAlgo::Sha1, "sha1"}, @@ -485,35 +485,35 @@ AllDigestAlgos = {{ { MimeCertificate::DigestAlgo::Crc32, "crc32"}, { MimeCertificate::DigestAlgo::Crc32Rfc1510, "crc32-rfc1510"}, { MimeCertificate::DigestAlgo::Crc32Rfc2440, "crc32-rfc2440"}, - }}; + }); constexpr Option to_string_view_opt(MimeCertificate::DigestAlgo algo) { return to_string_view_opt(AllDigestAlgos, algo); } -constexpr std::array, 6> -AllTrusts = {{ +inline constexpr auto +AllTrusts = std::to_array>({ { MimeCertificate::Trust::Unknown, "unknown" }, { MimeCertificate::Trust::Undefined, "undefined" }, { MimeCertificate::Trust::Never, "never" }, { MimeCertificate::Trust::Marginal, "marginal" }, { MimeCertificate::Trust::TrustFull, "trust-full" }, { MimeCertificate::Trust::TrustUltimate,"trust-ultimate" }, - }}; + }); constexpr Option to_string_view_opt(MimeCertificate::Trust trust) { return to_string_view_opt(AllTrusts, trust); } -constexpr std::array, 6> -AllValidities = {{ +inline constexpr auto +AllValidities = std::to_array>({ { MimeCertificate::Validity::Unknown, "unknown" }, { MimeCertificate::Validity::Undefined, "undefined" }, { MimeCertificate::Validity::Never, "never" }, { MimeCertificate::Validity::Marginal, "marginal" }, { MimeCertificate::Validity::Full, "full" }, { MimeCertificate::Validity::Ultimate, "ultimate" }, - }}; + }); constexpr Option to_string_view_opt(MimeCertificate::Validity val) { return to_string_view_opt(AllValidities, val); @@ -566,8 +566,8 @@ private: } }; -constexpr std::array, 12> -AllMimeSignatureStatuses= {{ +inline constexpr auto +AllMimeSignatureStatuses = std::to_array>({ { MimeSignature::Status::Valid, "valid" }, { MimeSignature::Status::Green, "green" }, { MimeSignature::Status::Red, "red" }, @@ -580,10 +580,10 @@ AllMimeSignatureStatuses= {{ { MimeSignature::Status::BadPolicy, "bad-policy" }, { MimeSignature::Status::SysError, "sys-error" }, { MimeSignature::Status::TofuConflict, "tofu-confict" }, - }}; + }); MU_ENABLE_BITOPS(MimeSignature::Status); -static inline std::string to_string(MimeSignature::Status status) { +inline std::string to_string(MimeSignature::Status status) { std::string str; for (auto&& item: AllMimeSignatureStatuses) { if (none_of(item.first & status)) @@ -649,8 +649,8 @@ private: } }; -constexpr std::array, 12> -AllCipherAlgos= {{ +inline constexpr auto +AllCipherAlgos = std::to_array>({ {MimeDecryptResult::CipherAlgo::Default, "default"}, {MimeDecryptResult::CipherAlgo::Idea, "idea"}, {MimeDecryptResult::CipherAlgo::Des3, "3des"}, @@ -663,7 +663,7 @@ AllCipherAlgos= {{ {MimeDecryptResult::CipherAlgo::Camellia128, "camellia128"}, {MimeDecryptResult::CipherAlgo::Camellia192, "camellia192"}, {MimeDecryptResult::CipherAlgo::Camellia256, "camellia256"}, - }}; + }); constexpr Option to_string_view_opt(MimeDecryptResult::CipherAlgo algo) { return to_string_view_opt(AllCipherAlgos, algo); diff --git a/lib/message/mu-priority.hh b/lib/message/mu-priority.hh index a4bded34..c1dc91bf 100644 --- a/lib/message/mu-priority.hh +++ b/lib/message/mu-priority.hh @@ -44,8 +44,8 @@ enum struct Priority : char { /** * Sequence of all message priorities. */ -static constexpr std::array AllMessagePriorities = { - Priority::Low, Priority::Normal, Priority::High}; +inline constexpr auto AllMessagePriorities = std::to_array({ + Priority::Low, Priority::Normal, Priority::High}); /** * Get the char for some priority @@ -88,7 +88,7 @@ priority_from_char(char c) * * @return the priority or none */ -static inline Option +inline Option priority_from_name(std::string_view pname) { if (pname == "low" || pname == "l") diff --git a/lib/message/test-mu-message.cc b/lib/message/test-mu-message.cc index c562ba25..e09e9758 100644 --- a/lib/message/test-mu-message.cc +++ b/lib/message/test-mu-message.cc @@ -1020,8 +1020,8 @@ abc const auto id2{m2->message_id()}; const auto id3{m3->message_id()}; - g_assert_true(g_str_has_suffix(id2.c_str(), "@mu.id")); - g_assert_true(g_str_has_suffix(id3.c_str(), "@mu.id")); + g_assert_true(id2.ends_with("@mu.id")); + g_assert_true(id3.ends_with("@mu.id")); } diff --git a/lib/mu-maildir.cc b/lib/mu-maildir.cc index 91a2e51d..af3325b5 100644 --- a/lib/mu-maildir.cc +++ b/lib/mu-maildir.cc @@ -71,7 +71,7 @@ create_maildir(const std::string& path, mode_t mode) if (path.empty()) return Err(Error{Error::Code::File, "path must not be empty"}); - std::array subdirs = {"new", "cur", "tmp"}; + const auto subdirs = std::to_array({"new", "cur", "tmp"}); for (auto&& subdir: subdirs) { const auto fullpath{join_paths(path, subdir)}; @@ -274,7 +274,7 @@ msg_move_verify(const std::string& src, const std::string& dst) // valgrind warning in tests /* use GIO to move files; this is slower than rename() so only use * this when needed: when moving across filesystems */ -G_GNUC_UNUSED static Mu::Result +[[maybe_unused]] static Mu::Result msg_move_g_file(const std::string& src, const std::string& dst) { GFile *srcfile{g_file_new_for_path(src.c_str())}; @@ -296,7 +296,7 @@ msg_move_g_file(const std::string& src, const std::string& dst) /* use mv to move files; this is slower than rename() so only use this when * needed: when moving across filesystems */ -G_GNUC_UNUSED static Mu::Result +[[maybe_unused]] static Mu::Result msg_move_mv_file(const std::string& src, const std::string& dst) { static const auto mv_path{program_in_path("mv")}; @@ -407,7 +407,7 @@ check_determine_target_params (const std::string& old_path, "target maildir must be empty or start with / ({})", target_maildir}); - if (old_path.find(root_maildir_path) != 0) + if (!old_path.starts_with(root_maildir_path)) return Err(Error{Error::Code::File, "old-path must be below root-maildir ({}) ({})", old_path, root_maildir_path}); diff --git a/lib/mu-query-parser.cc b/lib/mu-query-parser.cc index 3da4689f..193d310b 100644 --- a/lib/mu-query-parser.cc +++ b/lib/mu-query-parser.cc @@ -54,9 +54,9 @@ static bool looks_like_matcher(const Sexp& sexp) { // all the "terminal values" (from the Mu parser's pov) - const std::array value_syms = { + const auto value_syms = std::to_array({ placeholder_sym, phrase_sym, regex_sym, range_sym, wildcard_sym - }; + }); if (!sexp.listp() || sexp.empty() || !sexp.front().symbolp()) return false; diff --git a/lib/mu-query-parser.hh b/lib/mu-query-parser.hh index 79c5e46b..fc8747ea 100644 --- a/lib/mu-query-parser.hh +++ b/lib/mu-query-parser.hh @@ -28,20 +28,20 @@ namespace Mu { /* * Some useful symbol-sexps */ -static inline const auto placeholder_sym = "_"_sym; -static inline const auto phrase_sym = "phrase"_sym; -static inline const auto regex_sym = "regex"_sym; -static inline const auto range_sym = "range"_sym; -static inline const auto wildcard_sym = "wildcard"_sym; +inline const auto placeholder_sym = "_"_sym; +inline const auto phrase_sym = "phrase"_sym; +inline const auto regex_sym = "regex"_sym; +inline const auto range_sym = "range"_sym; +inline const auto wildcard_sym = "wildcard"_sym; -static inline const auto open_sym = "("_sym; -static inline const auto close_sym = ")"_sym; +inline const auto open_sym = "("_sym; +inline const auto close_sym = ")"_sym; -static inline const auto and_sym = "and"_sym; -static inline const auto or_sym = "or"_sym; -static inline const auto xor_sym = "xor"_sym; -static inline const auto not_sym = "not"_sym; -static inline const auto and_not_sym = "and-not"_sym; +inline const auto and_sym = "and"_sym; +inline const auto or_sym = "or"_sym; +inline const auto xor_sym = "xor"_sym; +inline const auto not_sym = "not"_sym; +inline const auto and_not_sym = "and-not"_sym; /* diff --git a/lib/mu-query-processor.cc b/lib/mu-query-processor.cc index 33d71400..80b0c07c 100644 --- a/lib/mu-query-processor.cc +++ b/lib/mu-query-processor.cc @@ -93,18 +93,8 @@ struct Element { Range >; - // helper - template - struct decay_equiv: - std::is_same::type, U>::type {}; - Element(Bracket b): value{b} {} Element(Op op): value{op} {} - - template, T>::value>::type = 0> - Element(const std::string& field, const T& val): value{T{field, val}} {} - Element(const std::string& val): value{val} {} template diff --git a/lib/mu-query-results.hh b/lib/mu-query-results.hh index 4ebb0c2a..b514d09c 100644 --- a/lib/mu-query-results.hh +++ b/lib/mu-query-results.hh @@ -109,7 +109,7 @@ QueryMatch::has_flag(QueryMatch::Flags flag) const } /* LCOV_EXCL_START */ -static inline std::ostream& +inline std::ostream& operator<<(std::ostream& os, QueryMatch::Flags mflags) { if (mflags == QueryMatch::Flags::None) { @@ -384,7 +384,7 @@ private: }; -static inline auto +inline auto format_as(const QueryResultsIterator& it) { return it.path().value_or(""); diff --git a/lib/mu-query-threads.cc b/lib/mu-query-threads.cc index 6d992816..ed6c7046 100644 --- a/lib/mu-query-threads.cc +++ b/lib/mu-query-threads.cc @@ -637,7 +637,7 @@ struct MockQueryResult { using MockQueryResults = std::vector; -G_GNUC_UNUSED static std::ostream& +[[maybe_unused]] static std::ostream& operator<<(std::ostream& os, const MockQueryResults& qrs) { for (auto&& mi : qrs) diff --git a/lib/mu-query-xapianizer.cc b/lib/mu-query-xapianizer.cc index d18b6122..510a9c67 100644 --- a/lib/mu-query-xapianizer.cc +++ b/lib/mu-query-xapianizer.cc @@ -177,12 +177,12 @@ range(const Field& field, Sexp&& s) using OpPair = std::pair; -static constexpr std::array LogOpPairs = {{ +static constexpr auto LogOpPairs = std::to_array({ { "and", Xapian::Query::OP_AND }, { "or", Xapian::Query::OP_OR }, { "xor", Xapian::Query::OP_XOR }, { "not", Xapian::Query::OP_AND_NOT } - }}; + }); static Option find_log_op(const std::string& opname) diff --git a/lib/mu-script.cc b/lib/mu-script.cc index 81d481bc..e69b1488 100644 --- a/lib/mu-script.cc +++ b/lib/mu-script.cc @@ -68,7 +68,7 @@ get_info(std::string&& path, const std::string& prefix) std::string line; while (std::getline(file, line)) { - if (line.find(prefix) != 0) + if (!line.starts_with(prefix)) continue; line = line.substr(prefix.length()); diff --git a/lib/mu-server.cc b/lib/mu-server.cc index 9af1d48d..f302cb3a 100644 --- a/lib/mu-server.cc +++ b/lib/mu-server.cc @@ -682,7 +682,6 @@ struct FindProps { Field::Id sort_field_id{Field::Id::Date}; QueryFlags flags{QueryFlags::SkipUnreadable}; }; -// XXX: once we move to C++20, use designated initializers static const std::pair flags_props[] = { @@ -702,20 +701,17 @@ static const std::pair flags_props[] = { static FindProps determine_find_props(const Command& cmd) { - FindProps props{}; + const auto batch_size{cmd.number_arg(":batch-size").value_or(200)}; + if (batch_size < 1) + throw Error{Error::Code::InvalidArgument, "invalid batch-size {}", batch_size}; - props.query = cmd.string_arg(":query").value_or(""); - props.batch_size = cmd.number_arg(":batch-size").value_or(200); - if (props.batch_size < 1) - throw Error{Error::Code::InvalidArgument, "invalid batch-size {}", props.batch_size}; - - props.maxnum = cmd.number_arg(":maxnum").value_or(-1) /*unlimited*/; - if (props.maxnum < -1) - throw Error{Error::Code::InvalidArgument, "invalid max-num {}", props.maxnum}; + const auto maxnum{cmd.number_arg(":maxnum").value_or(-1) /*unlimited*/}; + if (maxnum < -1) + throw Error{Error::Code::InvalidArgument, "invalid max-num {}", maxnum}; const auto threads{cmd.boolean_arg(":threads")}; // complicated! - props.sort_field_id = std::invoke([&]()->Field::Id { + const auto sort_field_id = std::invoke([&]()->Field::Id { if (const auto arg = cmd.symbol_arg(":sortfield"); !arg) return Field::Id::Date; else if (arg->length() < 2) @@ -735,12 +731,19 @@ determine_find_props(const Command& cmd) return field->id; }); + auto flags{QueryFlags::SkipUnreadable}; for (const auto& item: flags_props) { if (cmd.boolean_arg(item.second)) - props.flags |= item.first; + flags |= item.first; } - return props; + return FindProps{ + .query = cmd.string_arg(":query").value_or(""), + .batch_size = batch_size, + .maxnum = maxnum, + .sort_field_id = sort_field_id, + .flags = flags, + }; } /** diff --git a/lib/mu-store-labels.cc b/lib/mu-store-labels.cc index c3f04653..11f125c3 100644 --- a/lib/mu-store-labels.cc +++ b/lib/mu-store-labels.cc @@ -202,11 +202,11 @@ Mu::import_labels(Mu::Store& store, const std::string& path, bool dry_run, bool while (std::getline(input, line)) { - if (line.find(path_key) == 0) + if (line.starts_with(path_key)) current_path = line.substr(path_key.length()); - else if (line.find(message_id_key) == 0) + else if (line.starts_with(message_id_key)) current_msgid = line.substr(message_id_key.length()); - else if (line.find(labels_key) == 0) { + else if (line.starts_with(labels_key)) { current_labels = split(line.substr(labels_key.length()), ','); if (!current_labels.empty()) import_labels_for_message(store, dry_run, level, diff --git a/lib/mu-store.hh b/lib/mu-store.hh index f2c82cfc..03f26ce0 100644 --- a/lib/mu-store.hh +++ b/lib/mu-store.hh @@ -571,7 +571,7 @@ private: MU_ENABLE_BITOPS(Store::Options); MU_ENABLE_BITOPS(Store::MoveOptions); -static inline std::string +inline std::string format_as(const Store& store) { return mu_format("store ({}/{})", format_as(store.xapian_db()), diff --git a/lib/mu-xapian-db.hh b/lib/mu-xapian-db.hh index e71bef68..c7e1f631 100644 --- a/lib/mu-xapian-db.hh +++ b/lib/mu-xapian-db.hh @@ -132,8 +132,8 @@ struct MetadataIface { * These are special: handled on the Xapian db level * rather than Config */ - static inline constexpr std::string_view created_key = "created"; - static inline constexpr std::string_view last_change_key = "last-change"; + static constexpr std::string_view created_key = "created"; + static constexpr std::string_view last_change_key = "last-change"; }; @@ -534,7 +534,7 @@ format_as(XapianDb::Flavor flavor) } } -static inline std::string +inline std::string format_as(const XapianDb& db) { return mu_format("{} @ {}", db.description(), db.path()); diff --git a/lib/tests/test-mu-msg.cc b/lib/tests/test-mu-msg.cc index e1d06115..e46019a0 100644 --- a/lib/tests/test-mu-msg.cc +++ b/lib/tests/test-mu-msg.cc @@ -165,13 +165,13 @@ test_mu_msg_multimime() static void test_mu_msg_flags() { - std::array, 2> tests= {{ + auto tests = std::to_array>({ {MU_TESTMAILDIR4 "/multimime!2,FS", (Flags::Flagged | Flags::Seen | Flags::HasAttachment)}, {MU_TESTMAILDIR4 "/special!2,Sabc", (Flags::Seen)} - }}; + }); for (auto&& test: tests) { auto msg = Message::make_from_path(test.first); @@ -201,12 +201,12 @@ test_mu_msg_references() auto msg{Message::make_from_path(MU_TESTMAILDIR4 "/1305664394.2171_402.cthulhu!2,") .value()}; - std::array expected_refs = { + auto expected_refs = std::to_array({ "non-exist-01@msg.id", "non-exist-02@msg.id", "non-exist-03@msg.id", "non-exist-04@msg.id" - }; + }); assert_equal_seq_str(msg.references(), expected_refs); assert_equal(msg.thread_id(), expected_refs[0]); @@ -218,14 +218,14 @@ test_mu_msg_references_dups() auto msg{Message::make_from_path(MU_TESTMAILDIR4 "/1252168370_3.14675.cthulhu!2,S") .value()}; - std::array expected_refs = { + auto expected_refs = std::to_array({ "439C1136.90504@euler.org", "4399DD94.5070309@euler.org", "20051209233303.GA13812@gauss.org", "439B41ED.2080402@euler.org", "439A1E03.3090604@euler.org", "20051211184308.GB13513@gauss.org" - }; + }); assert_equal_seq_str(msg.references(), expected_refs); assert_equal(msg.thread_id(), expected_refs[0]); @@ -237,7 +237,7 @@ test_mu_msg_references_many() auto msg{Message::make_from_path(MU_TESTMAILDIR2 "/bar/cur/181736.eml") .value()}; - std::array expected_refs = { + auto expected_refs = std::to_array({ "e9065dac-13c1-4103-9e31-6974ca232a89@t15g2000prt.googlegroups.com", "87hbblwelr.fsf@sapphire.mobileactivedefense.com", "pql248-4va.ln1@wilbur.25thandClement.com", @@ -249,7 +249,7 @@ test_mu_msg_references_many() "tO8cp.1228$GE6.370@news.usenetserver.com", "ikr6ks$nlf$1@Iltempo.Update.UU.SE", "8ioh48-8mu.ln1@leafnode-msgid.gclare.org.uk" - }; + }); assert_equal_seq_str(msg.references(), expected_refs); assert_equal(msg.thread_id(), expected_refs[0]); @@ -268,12 +268,12 @@ test_mu_msg_tags() g_assert_true(msg.priority() == Priority::High); g_assert_cmpuint(msg.date(), ==, 1217530645); - std::array expected_tags = { + auto expected_tags = std::to_array({ "Paradise", "losT", "john", "milton" - }; + }); assert_equal_seq_str(msg.tags(), expected_tags); } @@ -368,7 +368,7 @@ k+ZGGoQ0v8b7RwmyskMAAAAAAAAAAAAA } -G_GNUC_UNUSED static gboolean +[[maybe_unused]] static gboolean ignore_error(const char* log_domain, GLogLevelFlags log_level, const gchar* msg, gpointer user_data) { return FALSE; /* don't abort */ diff --git a/lib/tests/test-mu-store-query.cc b/lib/tests/test-mu-store-query.cc index e356e514..586f098c 100644 --- a/lib/tests/test-mu-store-query.cc +++ b/lib/tests/test-mu-store-query.cc @@ -801,7 +801,7 @@ Boo! TempDir tdir; auto store{make_test_store(tdir.path(), test_msgs, {})}; /* true: match; false: no match */ - const auto cases = std::array, 8>{{ + const auto cases = std::to_array>({ {"subject:foo's", true}, {"subject:foo*", true}, {"subject:/foo/", true}, @@ -810,7 +810,7 @@ Boo! {"subject:/foo’s bar/", false}, /* <-- no matching, needs quoting */ {"subject:\"/foo’s bar/\"", true}, /* <-- this works, quote the regex */ {R"(subject:"/foo’s bar/")", true}, /* <-- this works, quote the regex */ - }}; + }); for (auto&& test: cases) { mu_debug("query: '{}'", test.first); diff --git a/lib/utils/mu-command-handler.hh b/lib/utils/mu-command-handler.hh index 778ad8b3..09515369 100644 --- a/lib/utils/mu-command-handler.hh +++ b/lib/utils/mu-command-handler.hh @@ -265,7 +265,7 @@ private: }; /* LCOV_EXCL_START */ -static inline std::ostream& +inline std::ostream& operator<<(std::ostream& os, const CommandHandler::ArgInfo& info) { os << info.type << " (" << (info.required ? "required" : "optional") << ")"; @@ -274,7 +274,7 @@ operator<<(std::ostream& os, const CommandHandler::ArgInfo& info) } /* LCOV_EXCL_STOP */ -static inline std::ostream& +inline std::ostream& operator<<(std::ostream& os, const CommandHandler::CommandInfo& info) { for (auto&& arg : info.args) @@ -284,7 +284,7 @@ operator<<(std::ostream& os, const CommandHandler::CommandInfo& info) return os; } -static inline std::ostream& +inline std::ostream& operator<<(std::ostream& os, const CommandHandler::CommandInfoMap& map) { for (auto&& c : map) diff --git a/lib/utils/mu-error.hh b/lib/utils/mu-error.hh index 50719024..23fb3c84 100644 --- a/lib/utils/mu-error.hh +++ b/lib/utils/mu-error.hh @@ -183,7 +183,7 @@ private: std::string hint_; }; -static inline auto +inline auto format_as(const Error& err) { return mu_format("<{} ({}:{})>", err.what(), diff --git a/lib/utils/mu-html-to-text.cc b/lib/utils/mu-html-to-text.cc index ad773a4b..51106905 100644 --- a/lib/utils/mu-html-to-text.cc +++ b/lib/utils/mu-html-to-text.cc @@ -222,7 +222,7 @@ private: }; -G_GNUC_UNUSED static auto +[[maybe_unused]] static auto format_as(const Context& ctx) { return mu_format("<{}:{}: '{}'>", @@ -335,18 +335,18 @@ comment(Context& ctx) static bool // do we need a SPC separator for this tag? needs_separator(std::string_view tagname) { - constexpr std::array nosep_tags = { + constexpr auto nosep_tags = std::to_array({ "b", "em", "i", "s", "strike", "tt", "u" - }; + }); return !seq_some(nosep_tags, [&](auto&& t){return matches(tagname, t);}); } static bool // do we need to skip the element completely? is_skip_element(std::string_view tagname) { - constexpr std::array skip_tags = { + constexpr auto skip_tags = std::to_array({ "script", "style", "head", "meta" - }; + }); return seq_some(skip_tags, [&](auto&& t){return matches(tagname, t);}); } @@ -423,7 +423,7 @@ html_escape_char(Context& ctx) { // we only care about a few accented chars, and add them unaccented, lowercase, since that's // we do for indexing anyway. - constexpr std::array escs = { + constexpr auto escs = std::to_array({ "breve", "caron", "circ", @@ -435,7 +435,7 @@ html_escape_char(Context& ctx) "strok", "tilde", "uml", - }; + }); auto unescape=[escs](std::string_view esc)->char { if (esc.empty()) diff --git a/lib/utils/mu-option.hh b/lib/utils/mu-option.hh index 32b1beea..ce9b4d74 100644 --- a/lib/utils/mu-option.hh +++ b/lib/utils/mu-option.hh @@ -55,7 +55,7 @@ unwrap(Option&& res) * @return option with either the string or nothing if str was NULL. */ Option -static inline to_string_opt(const char* str) { +inline to_string_opt(const char* str) { if (str) return std::string{str}; else diff --git a/lib/utils/mu-regex.hh b/lib/utils/mu-regex.hh index 45ad20db..e0da7be5 100644 --- a/lib/utils/mu-regex.hh +++ b/lib/utils/mu-regex.hh @@ -178,7 +178,7 @@ private: GRegex *rx_{}; }; -static inline std::string format_as(const Regex& rx) { +inline std::string format_as(const Regex& rx) { if (auto&& grx{rx.g_regex()}; !grx) return "//"; else diff --git a/lib/utils/mu-result.hh b/lib/utils/mu-result.hh index 887f8ad0..34b24451 100644 --- a/lib/utils/mu-result.hh +++ b/lib/utils/mu-result.hh @@ -48,7 +48,7 @@ Ok(T&& t) * * @return a success Result */ -static inline Result +inline Result Ok() { return {}; @@ -72,27 +72,27 @@ Err(const Error& err) return tl::unexpected(err); } -static inline tl::unexpected +inline tl::unexpected Err(Error&& err) { return tl::unexpected(std::move(err)); } -static inline tl::unexpected +inline tl::unexpected Err(const Error& err) { return tl::unexpected(err); } template -static inline tl::unexpected +inline tl::unexpected Err(const Result& res) { return res.error(); } template -static inline tl::unexpected +inline tl::unexpected Err(Result&& res) { return std::move(res.error()); diff --git a/lib/utils/mu-sexp.hh b/lib/utils/mu-sexp.hh index 77c8a8e2..8e3eaab5 100644 --- a/lib/utils/mu-sexp.hh +++ b/lib/utils/mu-sexp.hh @@ -101,7 +101,7 @@ struct Sexp { Sexp(const char *str): Sexp{std::string{str}} {} Sexp(std::string_view sv): Sexp{std::string{sv}} {} - template> > + template Sexp(N n):value{static_cast(n)} {} Sexp(const Symbol& sym): value{sym} {} @@ -305,13 +305,13 @@ MU_ENABLE_BITOPS(Sexp::Format); /** * String-literal; allow for ":foo"_sym to be a symbol */ -static inline Sexp::Symbol +inline Sexp::Symbol operator""_sym(const char* str, std::size_t n) { return Sexp::Symbol{str}; } -static inline std::ostream& +inline std::ostream& operator<<(std::ostream& os, const Sexp::Type& stype) { os << Sexp::type_name(stype); @@ -319,7 +319,7 @@ operator<<(std::ostream& os, const Sexp::Type& stype) } -static inline std::ostream& +inline std::ostream& operator<<(std::ostream& os, const Sexp& sexp) { os << sexp.to_string(); diff --git a/lib/utils/mu-test-utils.hh b/lib/utils/mu-test-utils.hh index 0774f79c..c62bd57c 100644 --- a/lib/utils/mu-test-utils.hh +++ b/lib/utils/mu-test-utils.hh @@ -86,7 +86,7 @@ bool set_en_us_utf8_locale(); * * @return number of newlines */ -static inline size_t count_nl(const std::string& s) { +inline size_t count_nl(const std::string& s) { return std::count(s.begin(), s.end(), '\n'); } @@ -167,7 +167,7 @@ private: const bool autodelete_; }; -static inline auto format_as(const TempDir& td) { +inline auto format_as(const TempDir& td) { return td.path(); } diff --git a/lib/utils/mu-unbroken.hh b/lib/utils/mu-unbroken.hh index 7c431d46..ad70cfa5 100644 --- a/lib/utils/mu-unbroken.hh +++ b/lib/utils/mu-unbroken.hh @@ -37,7 +37,7 @@ * * @return true or false */ -static inline bool +inline bool is_unbroken_script(unsigned p) { // Array containing the last value in each range of codepoints which diff --git a/lib/utils/mu-utils-file.cc b/lib/utils/mu-utils-file.cc index c400dcea..b2b341b6 100644 --- a/lib/utils/mu-utils-file.cc +++ b/lib/utils/mu-utils-file.cc @@ -201,7 +201,7 @@ Mu::read_from_stdin() */ /*LCOV_EXCL_START*/ static void -maybe_setsid (G_GNUC_UNUSED gpointer user_data) +maybe_setsid ([[maybe_unused]] gpointer user_data) { #if HAVE_SETSID setsid(); diff --git a/lib/utils/mu-utils-file.hh b/lib/utils/mu-utils-file.hh index 86b6b11f..6bf06580 100644 --- a/lib/utils/mu-utils-file.hh +++ b/lib/utils/mu-utils-file.hh @@ -151,7 +151,7 @@ std::string runtime_path(RuntimePath path, const std::string& muhome=""); * * @return the path */ -static inline std::string join_paths() { return {}; } +inline std::string join_paths() { return {}; } template std::string join_paths_(S&& s) { return std::string{s}; } template std::string join_paths_(S&& s, Args...args) { diff --git a/lib/utils/mu-utils.hh b/lib/utils/mu-utils.hh index 33488dfb..b276cf0b 100644 --- a/lib/utils/mu-utils.hh +++ b/lib/utils/mu-utils.hh @@ -303,7 +303,7 @@ using StringVec = std::vector; * @return true or false */ bool contains_unbroken_script(const char* str); -static inline bool contains_unbroken_script(const std::string& str) { +inline bool contains_unbroken_script(const std::string& str) { return contains_unbroken_script(str.c_str()); } @@ -315,7 +315,7 @@ static inline bool contains_unbroken_script(const std::string& str) { * * @return a utf8-string */ -static inline std::string utf8_clean(std::string&& str) { +inline std::string utf8_clean(std::string&& str) { if (!g_utf8_validate(str.c_str(), static_cast(str.length()), {})) { gchar* clean{g_utf8_make_valid( str.c_str(), static_cast(str.length()))}; @@ -333,7 +333,7 @@ static inline std::string utf8_clean(std::string&& str) { * @return a flattened string */ std::string utf8_flatten(const char* str); -static inline std::string +inline std::string utf8_flatten(const std::string& s) { return utf8_flatten(s.c_str()); } @@ -401,7 +401,7 @@ std::vector split(const std::string& str, char sepa); */ [[nodiscard]] std::string join(const std::vector& svec, const std::string& sepa); -[[nodiscard]] static inline std::string join(const std::vector& svec, +[[nodiscard]] inline std::string join(const std::vector& svec, char sepa) { return join(svec, std::string(1, sepa)); } @@ -426,7 +426,7 @@ bool fputs_encoded (const std::string& str, FILE *stream); * @return true if printing worked, false otherwise */ template -static inline bool mu_print_encoded(fmt::format_string frm, T&&... args) noexcept { +inline bool mu_print_encoded(fmt::format_string frm, T&&... args) noexcept { return fputs_encoded(fmt::format(frm, std::forward(args)...), stdout); } @@ -613,7 +613,7 @@ void set_thread_name(const std::string& name); * @return a std::string */ template -static inline std::string +inline std::string to_string(const T& val) { std::stringstream sstr; diff --git a/lib/utils/tests/test-utils.cc b/lib/utils/tests/test-utils.cc index 70a659d1..c966a4e1 100644 --- a/lib/utils/tests/test-utils.cc +++ b/lib/utils/tests/test-utils.cc @@ -104,7 +104,7 @@ test_date_ymwdhMs() }; - const std::array cases = {{ + const auto cases = std::to_array({ {"7s", 7, 1}, {"3M", 3 * 60, 1}, {"3h", 3 * 60 * 60, 1}, @@ -112,7 +112,7 @@ test_date_ymwdhMs() {"2w", 2 * 7 * 24 * 60 * 60, 3600 + 1}, {"2y", 2 * 365 * 24 * 60 * 60, 24 * 3600 + 1}, {"3m", 3 * 30 * 24 * 60 * 60, 3 * 24 * 3600 + 1} - }}; + }); for (auto&& tcase: cases) { const auto date = parse_date_time(tcase.expr, true); @@ -132,14 +132,14 @@ test_date_ymwdhMs() static void test_parse_size() { - constexpr std::array, 6> cases = {{ + constexpr auto cases = std::to_array>({ { "456", false, 456 }, { "", false, G_MAXINT64 }, { "", true, 0 }, { "2K", false, 2048 }, { "2M", true, 2097152 }, { "5G", true, 5368709120 } - }}; + }); for(auto&& test: cases) { g_assert_cmpint(parse_size(std::get<0>(test), std::get<1>(test)) .value_or(-1), ==, std::get<2>(test)); @@ -154,7 +154,7 @@ test_utf8_clean() { assert_equal(utf8_clean("James Holden"), "James Holden"); - const std::array invalid_bytes ={ 'a' , static_cast(0xff), 'c'}; + const auto invalid_bytes = std::to_array({ 'a' , static_cast(0xff), 'c'}); std::string invalid{invalid_bytes.data(), invalid_bytes.size()}; g_assert_false(g_utf8_validate(invalid.c_str(), invalid.length(), nullptr)); diff --git a/mu/mu-cmd-view.cc b/mu/mu-cmd-view.cc index 3ddd78e1..27fcfca0 100644 --- a/mu/mu-cmd-view.cc +++ b/mu/mu-cmd-view.cc @@ -121,7 +121,7 @@ body_or_summary(const Message& message, const Options& opts) print_field("Summary", summ, color); } else { mu_print_encoded("{}", body); - if (!g_str_has_suffix(body.c_str(), "\n")) + if (!body.ends_with('\n')) mu_println(""); } } diff --git a/mu/mu-options.cc b/mu/mu-options.cc index 4051881e..6c890f39 100644 --- a/mu/mu-options.cc +++ b/mu/mu-options.cc @@ -716,7 +716,7 @@ struct CommandInfo { std::string_view help; // std::function is not constexp-friendly - typedef void(*setup_func_t)(CLI::App&, Options&); + using setup_func_t = void(*)(CLI::App&, Options&); setup_func_t setup_func{}; }; diff --git a/mu/tests/test-mu-query.cc b/mu/tests/test-mu-query.cc index 5f04f86a..9de70f4c 100644 --- a/mu/tests/test-mu-query.cc +++ b/mu/tests/test-mu-query.cc @@ -111,10 +111,10 @@ run_and_count_matches(const std::string& xpath, return qres->size(); } -typedef struct { +struct QResults { const char* query; size_t count; /* expected number of matches */ -} QResults; +}; static void test_mu_query_01(void)