initial commit
This commit is contained in:
commit
2deb5d87fb
7
CMakeLists.txt
Normal file
7
CMakeLists.txt
Normal file
@ -0,0 +1,7 @@
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
project(cxxopts)
|
||||
|
||||
set(VERSION "0.0.1")
|
||||
|
||||
add_subdirectory(src)
|
||||
|
3
src/CMakeLists.txt
Normal file
3
src/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
||||
add_executable(cxxopts main.cpp)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
|
1
src/cxxopts.hpp
Normal file
1
src/cxxopts.hpp
Normal file
@ -0,0 +1 @@
|
||||
#include <regex>
|
34
src/main.cpp
Normal file
34
src/main.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "cxxopts.hpp"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
std::basic_regex<char> options("--([a-zA-Z][-a-zA-Z]+)|-([a-zA-Z]+)");
|
||||
std::match_results<const char*> result;
|
||||
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
std::cout << "Argument " << i << std::endl;
|
||||
std::regex_match(argv[i], result, options);
|
||||
std::cout << "empty = " << result.empty() << std::endl;
|
||||
std::cout << "size = " << result.size() << std::endl;
|
||||
|
||||
std::cout << "matches:" << std::endl;
|
||||
for (int j = 0; j != result.size(); ++j)
|
||||
{
|
||||
std::cout << result[j] << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (const std::regex_error& e)
|
||||
{
|
||||
std::cout << "regex_error: " << e.what() << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user