Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Extension with dots not working in validator #2363

Merged
merged 1 commit into from
Feb 12, 2021

Conversation

eseiler
Copy link
Member

@eseiler eseiler commented Feb 1, 2021

Resolves #2353

@eseiler eseiler requested review from a team and SGSSGene and removed request for a team February 1, 2021 15:39
@codecov
Copy link

codecov bot commented Feb 1, 2021

Codecov Report

Merging #2363 (fd2caef) into master (ea685e8) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2363   +/-   ##
=======================================
  Coverage   98.21%   98.21%           
=======================================
  Files         265      265           
  Lines       10798    10806    +8     
=======================================
+ Hits        10605    10613    +8     
  Misses        193      193           
Impacted Files Coverage Δ
include/seqan3/argument_parser/validators.hpp 92.30% <100.00%> (+0.30%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ea685e8...7bd4c66. Read the comment docs.

bool ext_found{false};

// Iterate over all possible extensions, starting with the longest. E.g., "foo.bar.baz", "bar.baz", "baz".
for (size_t pos = file_path.find("."); !ext_found && pos != std::string_view::npos; pos = file_path.find("."))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens here? Why not just iterate over the valid extensions and check each time if file_path ends with that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, yeah no idea. Probably the amalgamation of different ideas...

* \param str The string to be searched.
* \param suffix The suffix to be searched for.
* \returns `true` if `suffix` is a suffix of `str`, otherwise `false`.
* \sa https://en.cppreference.com/w/cpp/string/basic_string_view/ends_with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not behave as described, because it ignores case 💅🏻

@eseiler eseiler force-pushed the fix/argparse_ext branch 2 times, most recently from 0006ecf to 3c81880 Compare February 2, 2021 13:37
Copy link
Contributor

@SGSSGene SGSSGene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sieht gut aus ✔

@SGSSGene SGSSGene requested review from a team and marehr and removed request for a team February 5, 2021 12:47
Copy link
Member

@marehr marehr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this looks excellent. Can we use the ends_with definition from cppreference.com?

// Drop the dot.
std::string drop_less_ext = path.extension().string().substr(1);
std::string const path_as_string{path.filename().string()};
std::string_view file_path{path_as_string};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about all of this string_views, do we really need them?

I think it would be fine to use strings here.

std::ranges::equal(str.substr(str_length - suffix_length), suffix, [] (char const chr1, char const chr2)
{
return std::tolower(chr1) == std::tolower(chr2);
});
Copy link
Member

@marehr marehr Feb 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the definition from https://en.cppreference.com/w/cpp/string/basic_string_view/ends_with ?

size() >= sv.size() && compare(size() - sv.size(), npos, sv) == 0

One range less :)

Never mind we want case insensitivity.

* \param suffix The suffix to be searched for.
* \returns `true` if `suffix` is a suffix of `str`, otherwise `false`.
*/
bool string_ends_with(std::string_view str, std::string_view suffix) const
Copy link
Member

@marehr marehr Feb 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool string_ends_with(std::string_view str, std::string_view suffix) const
bool case_insensitive_string_ends_with(std::string_view str, std::string_view suffix) const

or something xD

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also implement as new std::char_traits that make the string case-insensitive https://en.cppreference.com/w/cpp/string/char_traits

@marehr marehr merged commit 94a4e22 into seqan:master Feb 12, 2021
@eseiler eseiler deleted the fix/argparse_ext branch May 14, 2021 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extensions with dot don't work in argument parser
4 participants