-
Notifications
You must be signed in to change notification settings - Fork 1
/
opt.h
34 lines (33 loc) · 1 KB
/
opt.h
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
/*
This project was under the GPL-2.0 License.
Copyright(c) 2022 Lampese.
Copyright(c) 2022 nu11ptr.
*/
#ifndef _LAMAOPT_H_
#define _LAMAOPT_H_
#include <map>
#include <string>
#include <vector>
namespace LampOpt {
typedef struct Arguments {
std::map<std::string, std::string> args;
Arguments() {}
explicit Arguments(const std::vector<std::string>& arg,
const std::map<std::string, std::string>& alias =
std::map<std::string, std::string>()) {
for (size_t i = 0; i < arg.size(); i++) {
size_t p = arg[i].find_first_of('=');
if (p == std::string::npos) {
if (alias.find(arg[i]) != alias.cend())args[alias.at(arg[i])] = "true";
else args[arg[i]] = "true";
} else {
std::string&& x = arg[i].substr(0, p);
if (alias.find(x) != alias.cend())
args[alias.at(x)] = arg[i].substr(p);
else args[x] = arg[i].substr(p);
}
}
}
} Arguments;
}; // namespace LampOpt
#endif