17 inline bool split_short(
const std::string ¤t, std::string &name, std::string &rest) {
18 if(current.size() > 1 && current[0] ==
'-' &&
valid_first_char(current[1])) {
19 name = current.substr(1, 1);
20 rest = current.substr(2);
27 inline bool split_long(
const std::string ¤t, std::string &name, std::string &value) {
28 if(current.size() > 2 && current.substr(0, 2) ==
"--" &&
valid_first_char(current[2])) {
29 auto loc = current.find_first_of(
'=');
30 if(loc != std::string::npos) {
31 name = current.substr(2, loc - 2);
32 value = current.substr(loc + 1);
34 name = current.substr(2);
44 if(current.size() > 1 && current[0] ==
'/' &&
valid_first_char(current[1])) {
45 auto loc = current.find_first_of(
':');
46 if(loc != std::string::npos) {
47 name = current.substr(1, loc - 1);
48 value = current.substr(loc + 1);
50 name = current.substr(1);
59 inline std::vector<std::string>
split_names(std::string current) {
60 std::vector<std::string> output;
62 while((val = current.find(
",")) != std::string::npos) {
63 output.push_back(
trim_copy(current.substr(0, val)));
64 current = current.substr(val + 1);
73 flags.erase(std::remove_if(flags.begin(),
75 [](
const std::string &name) {
76 return ((name.empty()) || (!(((name.find_first_of(
'{') != std::string::npos) &&
77 (name.back() ==
'}')) ||
81 std::vector<std::pair<std::string, std::string>> output;
82 output.reserve(flags.size());
83 for(
auto &flag : flags) {
84 auto def_start = flag.find_first_of(
'{');
85 std::string defval =
"false";
86 if((def_start != std::string::npos) && (flag.back() ==
'}')) {
87 defval = flag.substr(def_start + 1);
89 flag.erase(def_start, std::string::npos);
91 flag.erase(0, flag.find_first_not_of(
"-!"));
92 output.emplace_back(flag, defval);
98 inline std::tuple<std::vector<std::string>, std::vector<std::string>, std::string>
101 std::vector<std::string> short_names;
102 std::vector<std::string> long_names;
103 std::string pos_name;
105 for(std::string name : input) {
106 if(name.length() == 0) {
109 if(name.length() > 1 && name[0] ==
'-' && name[1] !=
'-') {
111 short_names.emplace_back(1, name[1]);
113 throw BadNameString::OneCharName(name);
114 }
else if(name.length() > 2 && name.substr(0, 2) ==
"--") {
115 name = name.substr(2);
117 long_names.push_back(name);
119 throw BadNameString::BadLongName(name);
120 }
else if(name ==
"-" || name ==
"--") {
121 throw BadNameString::DashesOnly(name);
123 if(pos_name.length() > 0)
124 throw BadNameString::MultiPositionalNames(name);
129 return std::tuple<std::vector<std::string>, std::vector<std::string>, std::string>(
130 short_names, long_names, pos_name);