mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-26 09:31:59 +00:00
36 lines
775 B
C++
36 lines
775 B
C++
#include "options.h"
|
|
|
|
#include <iostream>
|
|
|
|
std::unordered_map<std::string, std::string> ParseOptions(int argc,
|
|
char** argv) {
|
|
std::unordered_map<std::string, std::string> output;
|
|
|
|
std::string previous_arg;
|
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
std::string arg = argv[i];
|
|
|
|
if (arg[0] != '-') {
|
|
if (previous_arg.size() == 0) {
|
|
std::cerr << "Invalid arguments; switches must start with -"
|
|
<< std::endl;
|
|
exit(1);
|
|
}
|
|
|
|
output[previous_arg] = arg;
|
|
previous_arg = "";
|
|
}
|
|
else {
|
|
output[arg] = "";
|
|
previous_arg = arg;
|
|
}
|
|
}
|
|
|
|
return output;
|
|
}
|
|
|
|
bool HasOption(const std::unordered_map<std::string, std::string>& options,
|
|
const std::string& option) {
|
|
return options.find(option) != options.end();
|
|
} |