-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault_option_parser.cpp
More file actions
47 lines (41 loc) · 1.32 KB
/
default_option_parser.cpp
File metadata and controls
47 lines (41 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "pch.hpp"
#include "default_option_parser.hpp"
namespace be::cli {
OptionParseResult default_option_parser(const S& arg) {
OptionParseResult result;
result.is_long_option = false;
if (!arg.empty() && arg[0] == '-') {
result.prefix.append(1, '-');
if (arg.length() > 1 && arg[1] == '-') {
// long option
result.prefix.append(1, '-');
result.is_long_option = true;
auto first = arg.begin() + 2;
for (auto it = first, end = arg.end(); it != end; ++it) {
char c = *it;
if (c == '=' || c == ':') {
result.options.push_back(S(first, it));
result.values.push_back(S(it + 1, end));
break;
}
}
if (result.options.empty()) {
// didn't find value; use whole arg as option
result.options.push_back(S(first, arg.end()));
}
} else {
// short option
for (auto it = arg.begin() + 1, end = arg.end(); it != end; ++it) {
char c = *it;
if (c == '=' || c == ':') {
result.values.push_back(S(it + 1, end));
break;
} else {
result.options.push_back(S(1, c));
}
}
}
} // else not an option
return result;
}
} // be::cli