getting option adding working
This commit is contained in:
parent
de73da53b5
commit
db5477ddd8
@ -1,3 +1,3 @@
|
||||
add_executable(cxxopts main.cpp)
|
||||
add_executable(cxxopts main.cpp cxxopts.cpp)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
|
||||
|
||||
@ -1,10 +1,48 @@
|
||||
#include <regex>
|
||||
#include <set>
|
||||
|
||||
namespace cxxopts
|
||||
{
|
||||
std::basic_regex<char> option_matcher
|
||||
("--([a-zA-Z][-_a-zA-Z]+)(=(.*))?|-([a-zA-Z]+)");
|
||||
extern std::basic_regex<char> option_matcher;
|
||||
|
||||
std::basic_regex<char> option_specifier
|
||||
("(([a-zA-Z]),)?([a-zA-Z][-_a-zA-Z]+)");
|
||||
extern std::basic_regex<char> option_specifier;
|
||||
|
||||
class OptionAdder;
|
||||
|
||||
class Options
|
||||
{
|
||||
public:
|
||||
|
||||
void
|
||||
parse(int& argc, char**& argv);
|
||||
|
||||
OptionAdder
|
||||
add_options();
|
||||
|
||||
private:
|
||||
friend class OptionAdder;
|
||||
|
||||
std::set<char32_t> m_short;
|
||||
std::set<std::string> m_long;
|
||||
};
|
||||
|
||||
class OptionAdder
|
||||
{
|
||||
public:
|
||||
|
||||
OptionAdder(Options& options)
|
||||
: m_options(options)
|
||||
{
|
||||
}
|
||||
|
||||
OptionAdder&
|
||||
operator()
|
||||
(
|
||||
const std::string& opts,
|
||||
const std::string& desc
|
||||
);
|
||||
|
||||
private:
|
||||
Options& m_options;
|
||||
};
|
||||
}
|
||||
|
||||
11
src/main.cpp
11
src/main.cpp
@ -1,12 +1,21 @@
|
||||
#include <iostream>
|
||||
#include <locale>
|
||||
|
||||
#include "cxxopts.hpp"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
std::locale::global(std::locale(""));
|
||||
try
|
||||
{
|
||||
|
||||
cxxopts::option_matcher.imbue(std::locale(""));
|
||||
cxxopts::option_matcher.assign
|
||||
("--([[:alpha:]][-_[:alpha:]]+)(=(.*))?|-([a-zA-Z]+)",
|
||||
std::regex_constants::extended | std::regex_constants::ECMAScript |
|
||||
std::regex_constants::collate);
|
||||
std::cout << cxxopts::option_matcher.getloc().name() << std::endl;
|
||||
|
||||
std::match_results<const char*> result;
|
||||
|
||||
for (int i = 1; i < argc; ++i)
|
||||
@ -19,7 +28,7 @@ int main(int argc, char* argv[])
|
||||
std::cout << "matches:" << std::endl;
|
||||
for (int j = 0; j != result.size(); ++j)
|
||||
{
|
||||
std::cout << result[j] << std::endl;
|
||||
std::cout << "arg " << j << ": " << result[j] << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user