argparse.cc (763B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #include "argparse.h" 6 7 ArgParser::ArgParser(const std::vector<std::string>& arguments) { 8 for (size_t i = 0; i < arguments.size(); i++) { 9 std::string arg = arguments.at(i); 10 if (arg.find("--") == 0) { 11 // look for an option argument 12 if (i + 1 < arguments.size() && arguments.at(i + 1).find("--") != 0) { 13 programArgs_[arg] = arguments.at(i + 1); 14 i++; 15 } else { 16 programArgs_[arg] = ""; 17 } 18 } else { 19 // positional argument (e.g. required argument) 20 positionalArgs_.push_back(arg); 21 } 22 } 23 }