Fixed iterator usage.
This commit is contained in:
@@ -77,6 +77,7 @@ public:
|
|||||||
/// @return true if found, false otherwise.
|
/// @return true if found, false otherwise.
|
||||||
[[nodiscard]] bool contains(const std::string& token) const;
|
[[nodiscard]] bool contains(const std::string& token) const;
|
||||||
|
|
||||||
|
/// Searches for an argument that contains the given string.
|
||||||
[[nodiscard]] bool has_flag_contains(const std::string& match) const;
|
[[nodiscard]] bool has_flag_contains(const std::string& match) const;
|
||||||
|
|
||||||
/// Searches for an argument that contains the given string.
|
/// Searches for an argument that contains the given string.
|
||||||
|
10
main.cpp
10
main.cpp
@@ -11,11 +11,13 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
std::vector<std::string> fakeArgs {"hello!!", "--color", "#FFFFFF", "what's up?", "--color", "#420690", "Damn jit", "--color", "#FFFFFF"}; //{"--verbose", "--file", "thf", "bruhbruh"};
|
std::vector<std::string> fakeArgs {"--output", "console", "hello!!", "--color", "#FFFFFF", "what's up?", "--color", "#420690", "Damn jit", "--color", "#FFFFFF"}; //{"--verbose", "--file", "thf", "bruhbruh"};
|
||||||
|
|
||||||
|
|
||||||
ArgsParser args(fakeArgs);
|
ArgsParser args(fakeArgs);
|
||||||
|
|
||||||
|
auto output = args.consume_flag_arg("--output");
|
||||||
|
|
||||||
|
|
||||||
if (args.has_flag("--help")) {
|
if (args.has_flag("--help")) {
|
||||||
|
|
||||||
@@ -26,15 +28,15 @@ int main(int argc, char* argv[]) {
|
|||||||
//for (auto args.)
|
//for (auto args.)
|
||||||
|
|
||||||
for (auto& arg : args.get_remaining_args()) {
|
for (auto& arg : args.get_remaining_args()) {
|
||||||
if (arg == "--color")
|
if (arg == "--color") {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<std::string> color_codes = args.consume_flag_arg_multiple("--color");
|
std::vector<std::string> color_codes = args.consume_flag_arg_multiple("--color");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (args.has_flag("--file")) {
|
if (args.has_flag("--file")) {
|
||||||
if (args.has_flag_arg("--file")) {
|
if (args.has_flag_arg("--file")) {
|
||||||
auto filename = args.consume_flag_arg("--file");
|
auto filename = args.consume_flag_arg("--file");
|
||||||
|
@@ -79,7 +79,7 @@ std::optional<std::string> ArgsParser::consume_flag_arg(const std::string &flag)
|
|||||||
|
|
||||||
std::string ret_val = std::string(*it);
|
std::string ret_val = std::string(*it);
|
||||||
args.erase(std::remove(args.begin(), args.end(), flag), args.end());
|
args.erase(std::remove(args.begin(), args.end(), flag), args.end());
|
||||||
args.erase(it);
|
args.erase(std::remove(args.begin(), args.end(), ret_val), args.end());
|
||||||
|
|
||||||
return ret_val;
|
return ret_val;
|
||||||
}
|
}
|
||||||
@@ -143,8 +143,7 @@ std::vector<std::string> ArgsParser::consume_flag_arg_multiple(const std::string
|
|||||||
if (*it == flag) {
|
if (*it == flag) {
|
||||||
if (it != args.end()) {
|
if (it != args.end()) {
|
||||||
ret_val.push_back(*std::next(it, 1).base());
|
ret_val.push_back(*std::next(it, 1).base());
|
||||||
it = args.erase(it);
|
it = args.erase(it, it+1);
|
||||||
it = args.erase(it);
|
|
||||||
|
|
||||||
//args.erase(it);
|
//args.erase(it);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user