Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/config/codechecker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ analyze:
- --enable=bugprone
- --enable=clang-diagnostic-shadow
- --disable=bugprone-easily-swappable-parameters
- --disable=cert-dcl58-cpp
- --disable=clang-diagnostic-implicit-int-float-conversion
- --disable=clang-diagnostic-float-conversion
- --disable=clang-diagnostic-implicit-int-conversion
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/parser/solution3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ number_type to_number(range_type && range)
return s;
}();
number_type num;
auto res = std::from_chars(&str[0], &str[0] + str.size(), num);
auto res = std::from_chars(str.data(), str.data() + str.size(), num);

if (res.ec != std::errc{})
{
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/parser/solution4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ number_type to_number(range_type && range)
return s;
}();
number_type num;
auto res = std::from_chars(&str[0], &str[0] + str.size(), num);
auto res = std::from_chars(str.data(), str.data() + str.size(), num);

if (res.ec != std::errc{})
{
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/parser/solution5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ number_type to_number(range_type && range)
return s;
}();
number_type num;
auto res = std::from_chars(&str[0], &str[0] + str.size(), num);
auto res = std::from_chars(str.data(), str.data() + str.size(), num);

if (res.ec != std::errc{})
{
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/parser/solution6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ number_type to_number(range_type && range)
return s;
}();
number_type num;
auto res = std::from_chars(&str[0], &str[0] + str.size(), num);
auto res = std::from_chars(str.data(), str.data() + str.size(), num);

if (res.ec != std::errc{})
{
Expand Down
8 changes: 4 additions & 4 deletions include/sharg/detail/format_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ class format_help_base : public format_base
if (!meta.description.empty())
{
derived_t().print_section("Description");
for (auto desc : meta.description)
for (auto && desc : meta.description)
print_line(desc);
}

Expand All @@ -397,14 +397,14 @@ class format_help_base : public format_base
derived_t().print_section("Positional Arguments");

// each call will evaluate the function derived_t().print_list_item()
for (auto f : positional_option_calls)
for (auto && f : positional_option_calls)
f();

// There are always options because of the common options
derived_t().print_section("Options");

// each call will evaluate the function derived_t().print_list_item()
for (auto f : parser_set_up_calls)
for (auto && f : parser_set_up_calls)
f();

// print Common options after developer options
Expand All @@ -424,7 +424,7 @@ class format_help_base : public format_base
if (!meta.examples.empty())
{
derived_t().print_section("Examples");
for (auto example : meta.examples)
for (auto && example : meta.examples)
print_line(example);
}

Expand Down
3 changes: 2 additions & 1 deletion include/sharg/detail/format_html.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ class format_html : public format_help_base<format_html>
*/
std::string to_html(std::string const & input)
{
std::string buffer = escape_special_xml_chars(input);
// Todo: Input is escaped, but then not used. Same in SeqAn2. Why?
// std::string buffer = escape_special_xml_chars(input);
std::string result;
std::vector<std::string> open_tags; // acts as a stack of html tags

Expand Down
2 changes: 1 addition & 1 deletion include/sharg/detail/format_man.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class format_man : public format_help_base<format_man>
std::cout << " " << meta.version << "\" \"" << meta.man_page_title << "\"\n";

// Print NAME section.
std::cout << ".SH NAME\n" << meta.app_name << " \\- " << meta.short_description << std::endl;
std::cout << ".SH NAME\n" << meta.app_name << " \\- " << meta.short_description << '\n';
}

/*!\brief Prints a section title in man page format to std::cout.
Expand Down
14 changes: 5 additions & 9 deletions include/sharg/detail/format_parse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class format_parse : public format_base

std::string result{'['};
for (auto const & [key, value] : key_value_pairs)
result += std::string{key.data()} + ", ";
result += std::string{key} + ", ";
result.replace(result.size() - 2, 2, "]"); // replace last ", " by "]"
return result;
}();
Expand Down Expand Up @@ -402,11 +402,11 @@ class format_parse : public format_base
requires std::is_arithmetic_v<option_t> && istreamable<option_t>
option_parse_result parse_option_value(option_t & value, std::string const & in)
{
auto res = std::from_chars(&in[0], &in[in.size()], value);
auto res = std::from_chars(in.data(), in.data() + in.size(), value);

if (res.ec == std::errc::result_out_of_range)
return option_parse_result::overflow_error;
else if (res.ec == std::errc::invalid_argument || res.ptr != &in[in.size()])
else if (res.ec == std::errc::invalid_argument || res.ptr != in.data() + in.size())
return option_parse_result::error;

return option_parse_result::success;
Expand All @@ -424,14 +424,10 @@ class format_parse : public format_base
*/
option_parse_result parse_option_value(bool & value, std::string const & in)
{
if (in == "0")
if (in == "0" || in == "false")
value = false;
else if (in == "1")
else if (in == "1" || in == "true")
value = true;
else if (in == "true")
value = true;
else if (in == "false")
value = false;
else
return option_parse_result::error;

Expand Down
4 changes: 2 additions & 2 deletions include/sharg/detail/format_tdl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ auto to_tdl(std::integral auto v)
//!\copydetails sharg::detail::to_tdl
auto to_tdl(std::floating_point auto v)
{
return tdl::DoubleValue(v);
return tdl::DoubleValue(static_cast<double>(v));
}

//!\copydetails sharg::detail::to_tdl
Expand Down Expand Up @@ -339,7 +339,7 @@ class format_tdl : format_base
.description = std::accumulate(begin(meta.description),
end(meta.description),
std::string{},
[](auto a, auto v)
[](auto const & a, auto const & v)
{
return a + v + '\n';
}),
Expand Down
2 changes: 1 addition & 1 deletion include/sharg/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class parser
version_check_dev_decision{version_updates},
arguments{arguments}
{
add_subcommands(subcommands);
add_subcommands(std::move(subcommands));
info.app_name = app_name;
}

Expand Down
2 changes: 1 addition & 1 deletion include/sharg/std/charconv
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ inline from_chars_result from_chars_floating_point(char const * first,
if (*first == '+') // + is permitted in function strto[d/f/ld] but not in from_chars
return {last, std::errc::invalid_argument};

float tmp{};
value_type tmp{};
constexpr ptrdiff_t buffer_size = 100;
char buffer[buffer_size];

Expand Down
6 changes: 3 additions & 3 deletions include/sharg/validators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class file_validator_base
file_path.erase(0, 1);

// Store a string_view containing all extensions for a better error message.
std::string const all_extensions{file_path.substr(file_path.find(".") + 1)};
std::string const all_extensions{file_path.substr(file_path.find('.') + 1)};

// Compares the extensions in lower case.
auto case_insensitive_ends_with = [&](std::string const & ext)
Expand Down Expand Up @@ -601,7 +601,7 @@ class input_file_validator : public file_validator_base
* \details
* \experimentalapi{Experimental since version 1.0.}
*/
enum class output_file_open_options
enum class output_file_open_options : uint8_t
{
//!\brief Allow to overwrite the output file
open_or_create,
Expand Down Expand Up @@ -660,7 +660,7 @@ class output_file_validator : public file_validator_base
* \details
* \experimentalapi{Experimental since version 1.0.}
*/
explicit output_file_validator(output_file_open_options const mode, std::vector<std::string> const & extensions) :
explicit output_file_validator(output_file_open_options const mode, std::vector<std::string> extensions) :
open_mode{mode}
{
file_validator_base::extensions_str = detail::to_string(extensions);
Expand Down
12 changes: 6 additions & 6 deletions test/unit/detail/safe_filesystem_entry_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
TEST(safe_filesystem_entry, file)
{
sharg::test::tmp_filename tmp_file{"dummy.txt"};
std::filesystem::path my_file = tmp_file.get_path();
std::filesystem::path const & my_file = tmp_file.get_path();
{
std::ofstream file{my_file};
EXPECT_TRUE(std::filesystem::exists(my_file));
Expand All @@ -25,7 +25,7 @@ TEST(safe_filesystem_entry, file)
TEST(safe_filesystem_entry, file_already_removed)
{
sharg::test::tmp_filename tmp_file{"dummy.txt"};
std::filesystem::path my_file = tmp_file.get_path();
std::filesystem::path const & my_file = tmp_file.get_path();
{
EXPECT_FALSE(std::filesystem::exists(my_file));
sharg::detail::safe_filesystem_entry file_guard{my_file};
Expand All @@ -37,7 +37,7 @@ TEST(safe_filesystem_entry, file_already_removed)
TEST(safe_filesystem_entry, directory)
{
sharg::test::tmp_filename tmp_file{"dummy.txt"};
std::filesystem::path my_dir = tmp_file.get_path();
std::filesystem::path const & my_dir = tmp_file.get_path();
{
std::filesystem::create_directory(my_dir);
EXPECT_TRUE(std::filesystem::exists(my_dir));
Expand All @@ -50,7 +50,7 @@ TEST(safe_filesystem_entry, directory)
TEST(safe_filesystem_entry, directory_already_removed)
{
sharg::test::tmp_filename tmp_file{"dummy.txt"};
std::filesystem::path my_dir = tmp_file.get_path();
std::filesystem::path const & my_dir = tmp_file.get_path();
{
EXPECT_FALSE(std::filesystem::exists(my_dir));
sharg::detail::safe_filesystem_entry dir_guard{my_dir};
Expand All @@ -62,7 +62,7 @@ TEST(safe_filesystem_entry, directory_already_removed)
TEST(safe_filesystem_entry, remove)
{
sharg::test::tmp_filename tmp_file{"dummy.txt"};
std::filesystem::path my_file = tmp_file.get_path();
std::filesystem::path const & my_file = tmp_file.get_path();
{
std::ofstream file{my_file};
EXPECT_TRUE(std::filesystem::exists(my_file));
Expand All @@ -76,7 +76,7 @@ TEST(safe_filesystem_entry, remove)
TEST(safe_filesystem_entry, remove_all)
{
sharg::test::tmp_filename tmp_file{"dummy.txt"};
std::filesystem::path my_dir = tmp_file.get_path();
std::filesystem::path const & my_dir = tmp_file.get_path();
{
std::filesystem::create_directory(my_dir);
EXPECT_TRUE(std::filesystem::exists(my_dir));
Expand Down
2 changes: 1 addition & 1 deletion test/unit/detail/version_check_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class version_check_test : public sharg::test::test_fixture

void randomise_home_folder()
{
auto tmp_directory = tmp_file.get_path().parent_path();
auto const tmp_directory = tmp_file.get_path().parent_path();
std::string const base_path = tmp_directory.string();

if (setenv(sharg::detail::version_checker::home_env_name, base_path.data(), 1))
Expand Down
4 changes: 2 additions & 2 deletions test/unit/parser/format_parse_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -846,9 +846,9 @@ TEST_F(format_parse_test, executable_name)
bool flag{false};
auto parser = get_parser();

auto check = [&](std::string_view expected)
auto check = [&](std::string expected)
{
parser = sharg::parser{"test_parser", {expected.data(), "-t"}, sharg::update_notifications::off};
parser = sharg::parser{"test_parser", {expected, std::string{"-t"}}, sharg::update_notifications::off};
parser.add_flag(flag, sharg::config{.short_id = 't'});
EXPECT_NO_THROW(parser.parse());
auto & executable_name = sharg::detail::test_accessor::executable_name(parser);
Expand Down
32 changes: 16 additions & 16 deletions test/unit/parser/format_parse_validators_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ TEST_F(validator_test, input_file)
sharg::test::tmp_filename const tmp_name_hidden{".testbox.fasta"};
sharg::test::tmp_filename const tmp_name_multiple{"testbox.fasta.txt"};

std::filesystem::path const tmp_path{tmp_name.get_path()};
std::filesystem::path const tmp_path_2{tmp_name_2.get_path()};
std::filesystem::path const tmp_path_hidden{tmp_name_hidden.get_path()};
std::filesystem::path const tmp_path_multiple{tmp_name_multiple.get_path()};
std::filesystem::path const & tmp_path{tmp_name.get_path()};
std::filesystem::path const & tmp_path_2{tmp_name_2.get_path()};
std::filesystem::path const & tmp_path_hidden{tmp_name_hidden.get_path()};
std::filesystem::path const & tmp_path_multiple{tmp_name_multiple.get_path()};

{ // Open fstream to create files.
std::ofstream tmp_file{tmp_path};
Expand Down Expand Up @@ -133,8 +133,8 @@ TEST_F(validator_test, output_file)
sharg::test::tmp_filename const tmp_name_3{"testbox_3.fa"};
sharg::test::tmp_filename const hidden_name{".testbox.fasta"};

std::filesystem::path const not_existing_path{tmp_name.get_path()};
std::filesystem::path const existing_path{tmp_name_2.get_path()};
std::filesystem::path const & not_existing_path{tmp_name.get_path()};
std::filesystem::path const & existing_path{tmp_name_2.get_path()};

{ // Open fstream to create files.
std::ofstream tmp_file{existing_path};
Expand Down Expand Up @@ -279,7 +279,7 @@ TEST_F(validator_test, output_file)
TEST_F(validator_test, input_directory)
{
sharg::test::tmp_filename const tmp_name{"testbox.fasta"};
std::filesystem::path const tmp_path{tmp_name.get_path()};
std::filesystem::path const & tmp_path{tmp_name.get_path()};

{ // Open fstream to create files.
std::ofstream tmp_file{tmp_path};
Expand Down Expand Up @@ -321,7 +321,7 @@ TEST_F(validator_test, input_directory)
TEST_F(validator_test, output_directory)
{
sharg::test::tmp_filename const tmp_name{"testbox.fasta"};
std::filesystem::path const tmp_path{tmp_name.get_path()};
std::filesystem::path const & tmp_path{tmp_name.get_path()};

{ // Open fstream to create files.
std::ofstream tmp_file{tmp_path};
Expand All @@ -348,8 +348,8 @@ TEST_F(validator_test, output_directory)

// Parent path exists and is writable.
sharg::test::tmp_filename tmp_child_name{"dir/child_dir"};
std::filesystem::path tmp_child_dir{tmp_child_name.get_path()};
std::filesystem::path tmp_parent_path{tmp_child_dir.parent_path()};
std::filesystem::path const & tmp_child_dir{tmp_child_name.get_path()};
std::filesystem::path const tmp_parent_path{tmp_child_dir.parent_path()};

EXPECT_FALSE(std::filesystem::exists(tmp_parent_path));
EXPECT_THROW(my_validator(tmp_child_dir), sharg::validation_error);
Expand All @@ -375,7 +375,7 @@ TEST_F(validator_test, output_directory)
TEST_F(validator_test, inputfile_not_readable)
{
sharg::test::tmp_filename const tmp_name{"my_file.test"};
std::filesystem::path const tmp_path{tmp_name.get_path()};
std::filesystem::path const & tmp_path{tmp_name.get_path()};

{ // Open fstream to create files.
std::ofstream tmp_file{tmp_path};
Expand Down Expand Up @@ -413,15 +413,15 @@ TEST_F(validator_test, inputfile_not_regular)
TEST_F(validator_test, inputdir_not_existing)
{
sharg::test::tmp_filename const tmp_name{"dir"};
std::filesystem::path const not_existing_dir{tmp_name.get_path()};
std::filesystem::path const & not_existing_dir{tmp_name.get_path()};

EXPECT_THROW(sharg::input_directory_validator{}(not_existing_dir), sharg::validation_error);
}

TEST_F(validator_test, inputdir_not_readable)
{
sharg::test::tmp_filename const tmp_name{"dir"};
std::filesystem::path const tmp_dir{tmp_name.get_path()};
std::filesystem::path const & tmp_dir{tmp_name.get_path()};

std::filesystem::create_directory(tmp_dir);

Expand All @@ -448,7 +448,7 @@ TEST_F(validator_test, inputdir_not_readable)
TEST_F(validator_test, outputfile_not_writable)
{
sharg::test::tmp_filename const tmp_name{"my_file.test"};
std::filesystem::path const tmp_file{tmp_name.get_path()};
std::filesystem::path const & tmp_file{tmp_name.get_path()};

sharg::output_file_validator my_validator{sharg::output_file_open_options::create_new};

Expand All @@ -475,7 +475,7 @@ TEST_F(validator_test, outputfile_not_writable)
TEST_F(validator_test, output_parent_dir_not_writable)
{
sharg::test::tmp_filename const tmp_name{"dir"};
std::filesystem::path const tmp_dir{tmp_name.get_path()};
std::filesystem::path const & tmp_dir{tmp_name.get_path()};

sharg::output_file_validator my_validator{};

Expand Down Expand Up @@ -517,7 +517,7 @@ TEST_F(validator_test, output_parent_dir_not_writable)
TEST_F(validator_test, outputdir_not_writable)
{
sharg::test::tmp_filename const tmp_name{"dir"};
std::filesystem::path const tmp_dir{tmp_name.get_path()};
std::filesystem::path const & tmp_dir{tmp_name.get_path()};

std::filesystem::create_directory(tmp_dir);

Expand Down
Loading