Added ArgsParser class.
This commit is contained in:
28
Core/include/Core/ArgsParser.hpp
Normal file
28
Core/include/Core/ArgsParser.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <Core/Macros.hpp>
|
||||
|
||||
class ArgsParser
|
||||
{
|
||||
public:
|
||||
ArgsParser(int argc, char** argv);
|
||||
explicit ArgsParser(std::vector<std::string> argv);
|
||||
|
||||
explicit ArgsParser(const std::string& args_str);
|
||||
|
||||
explicit ArgsParser(const std::string& exec, const std::vector<std::string>& tok);
|
||||
|
||||
bool FlagPresent(const std::string& flag) const;
|
||||
|
||||
std::vector<std::string> GetFlags() const {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string executable;
|
||||
std::string full_args;
|
||||
std::vector<std::string> tokens;
|
||||
};
|
31
Core/src/Core/ArgsParser.cpp
Normal file
31
Core/src/Core/ArgsParser.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <Core/ArgsParser.hpp>
|
||||
|
||||
ArgsParser::ArgsParser(int argc, char **argv) {
|
||||
executable = std::string(argv[0]);
|
||||
tokens = std::vector<std::string>(argv + 1, argv + argc);
|
||||
for (auto& token : tokens)
|
||||
full_args.append(std::string(token).append(" "));
|
||||
}
|
||||
|
||||
ArgsParser::ArgsParser(std::vector<std::string> argv) {
|
||||
executable = argv[0];
|
||||
full_args = string_build(argv);
|
||||
tokens = {argv.begin() + 1, argv.end()};
|
||||
}
|
||||
|
||||
ArgsParser::ArgsParser(const std::string &args_str) {
|
||||
full_args = args_str;
|
||||
std::vector<std::string> temp_tokens = string_split(full_args, ' ');
|
||||
tokens = {temp_tokens.begin() + 1, temp_tokens.end()};
|
||||
}
|
||||
|
||||
ArgsParser::ArgsParser(const std::string &exec, const std::vector<std::string> &tok) {
|
||||
executable = exec;
|
||||
tokens = tok;
|
||||
for (auto& token : tokens)
|
||||
full_args.append(std::string(token).append(" "));
|
||||
}
|
||||
|
||||
bool ArgsParser::FlagPresent(const std::string &flag) const {
|
||||
return std::ranges::find(tokens, flag) != tokens.end();
|
||||
}
|
Reference in New Issue
Block a user