Skip to content

Commit

Permalink
[MISC] Remove some ranges dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
smehringer committed Jan 24, 2022
1 parent a3dedd1 commit af4756f
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 22 deletions.
3 changes: 1 addition & 2 deletions doc/tutorial/argument_parser/solution3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
template <typename number_type, typename range_type>
number_type to_number(range_type && range)
{
std::string str;
std::string str = [&range] () { std::string s; for (auto c : range) s.push_back(c); return s; }();
number_type num;
std::ranges::copy(range, std::cpp20::back_inserter(str));
auto res = std::from_chars(&str[0], &str[0] + str.size(), num);

if (res.ec != std::errc{})
Expand Down
3 changes: 1 addition & 2 deletions doc/tutorial/argument_parser/solution4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
template <typename number_type, typename range_type>
number_type to_number(range_type && range)
{
std::string str;
std::string str = [&range] () { std::string s; for (auto c : range) s.push_back(c); return s; }();
number_type num;
std::ranges::copy(range, std::cpp20::back_inserter(str));
auto res = std::from_chars(&str[0], &str[0] + str.size(), num);

if (res.ec != std::errc{})
Expand Down
3 changes: 1 addition & 2 deletions doc/tutorial/argument_parser/solution5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
template <typename number_type, typename range_type>
number_type to_number(range_type && range)
{
std::string str;
std::string str = [&range] () { std::string s; for (auto c : range) s.push_back(c); return s; }();
number_type num;
std::ranges::copy(range, std::cpp20::back_inserter(str));
auto res = std::from_chars(&str[0], &str[0] + str.size(), num);

if (res.ec != std::errc{})
Expand Down
3 changes: 1 addition & 2 deletions doc/tutorial/argument_parser/solution6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
template <typename number_type, typename range_type>
number_type to_number(range_type && range)
{
std::string str;
std::string str = [&range] () { std::string s; for (auto c : range) s.push_back(c); return s; }();
number_type num;
std::ranges::copy(range, std::cpp20::back_inserter(str));
auto res = std::from_chars(&str[0], &str[0] + str.size(), num);

if (res.ec != std::errc{})
Expand Down
2 changes: 1 addition & 1 deletion include/sharg/argument_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ class argument_parser
{
std::string arg{argv[i]};

if (std::ranges::find(subcommands, arg) != subcommands.end())
if (std::find(subcommands.begin(), subcommands.end(), arg) != subcommands.end())
{
sub_parser = std::make_unique<argument_parser>(info.app_name + "-" + arg,
argc - i,
Expand Down
7 changes: 2 additions & 5 deletions include/sharg/detail/format_help.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,17 +317,14 @@ class format_help : public format_help_base<format_help>

// Tokenize the text.
std::istringstream iss(text.c_str());
std::vector<std::string> tokens;
std::ranges::copy(std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>(),
std::cpp20::back_inserter(tokens));
std::vector<std::string> tokens{std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>()};

// Print the text.
assert(pos <= tab);
std::fill_n(out, tab - pos, ' '); // go to tab

pos = tab;
typedef std::vector<std::string>::const_iterator TConstIter;
for (TConstIter it = tokens.begin(); it != tokens.end(); ++it)
for (auto it = tokens.begin(); it != tokens.end(); ++it)
{
if (it == tokens.begin())
{
Expand Down
18 changes: 10 additions & 8 deletions include/sharg/validators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#pragma once

#include <seqan3/std/algorithm>
#include <fstream>
#include <regex>

Expand Down Expand Up @@ -355,7 +354,7 @@ class file_validator_base
};

// Check if requested extension is present.
if (std::ranges::find_if(extensions, case_insensitive_ends_with) == extensions.end())
if (std::find_if(extensions.begin(), extensions.end(), case_insensitive_ends_with) == extensions.end())
{
throw validation_error{"Expected one of the following valid extensions: " + extensions_str + "! Got " +
all_extensions + " instead!"};
Expand Down Expand Up @@ -429,12 +428,15 @@ class file_validator_base
{
size_t const suffix_length{suffix.size()};
size_t const str_length{str.size()};
return suffix_length > str_length ?
false :
std::ranges::equal(str.substr(str_length - suffix_length), suffix, [] (char const chr1, char const chr2)
{
return std::tolower(chr1) == std::tolower(chr2);
});

if (suffix_length > str_length)
return false;

for (size_t j = 0, s_start = str_length - suffix_length; j < suffix_length; ++j)
if (std::tolower(str[s_start + j]) != std::tolower(suffix[j]))
return false;

return true;
}

//!\brief Creates a std::string from the extensions list, e.g. "[ext, ext2]".
Expand Down

0 comments on commit af4756f

Please sign in to comment.