ccls/src/options.cc

31 lines
817 B
C++
Raw Normal View History

2017-04-09 02:24:32 +00:00
#include "options.h"
#include <loguru.hpp>
2017-04-09 02:24:32 +00:00
#include <iostream>
std::unordered_map<std::string, std::string> ParseOptions(int argc,
2017-09-22 01:14:57 +00:00
char** argv) {
2017-04-09 02:24:32 +00:00
std::unordered_map<std::string, std::string> output;
for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
if (arg[0] == '-') {
auto equal = arg.find('=');
if (equal != std::string::npos) {
output[arg.substr(0, equal)] = arg.substr(equal + 1);
} else if (i + 1 < argc && argv[i + 1][0] != '-')
output[arg] = argv[++i];
else
output[arg] = "";
2017-04-09 02:24:32 +00:00
}
}
return output;
}
bool HasOption(const std::unordered_map<std::string, std::string>& options,
2017-09-22 01:14:57 +00:00
const std::string& option) {
2017-04-09 02:24:32 +00:00
return options.find(option) != options.end();
}