|
- #pragma once
-
- #include <cppcore/conversion/convert_cast.h>
-
- #include "context.h"
-
- namespace cppargs
- {
-
- next_result context::next(std::string* key)
- {
- if (key)
- key->clear();
-
- if (index + 1 >= argc)
- return next_result::finished;
-
- ++index;
- arg = argv[index];
- value = nullptr;
-
- /* check argument */
- int i = 0;
- value = nullptr;
- while (arg[i] == '-')
- ++i;
-
- /* parse value */
- if (i == 1)
- {
- if (key)
- *key = std::string("-") + arg[1];
- if (arg[2] != '\0')
- value = &arg[2];
- return next_result::option_short;
- }
- else if (i == 2)
- {
- auto tmp = strchr(arg, '=');
- if (tmp)
- {
- value = tmp + 1;
- if (key)
- *key = std::string(arg, cppcore::convert_cast<size_t>(tmp - arg));
- }
- else if (key)
- {
- *key = arg;
- }
- return next_result::option_long;
- }
- else
- {
- return next_result::argument;
- }
- }
-
- }
|