diff options
Diffstat (limited to 'src/tools/singlejar/token_stream.h')
-rw-r--r-- | src/tools/singlejar/token_stream.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/tools/singlejar/token_stream.h b/src/tools/singlejar/token_stream.h index 5d6342c78d..23ee84d7ad 100644 --- a/src/tools/singlejar/token_stream.h +++ b/src/tools/singlejar/token_stream.h @@ -20,6 +20,7 @@ #include <string.h> #include <memory> #include <string> +#include <utility> #include <vector> #include "src/tools/singlejar/diag.h" @@ -223,6 +224,31 @@ class ArgTokenStream { return true; } + // Process --OPTION OPTARG1,OPTSUFF1 OPTARG2,OPTSUFF2 ... + // If a current token is --OPTION, push_back all subsequent tokens up to the + // next option to the OPTARGS array, splitting the OPTARG,OPTSUFF by a comma, + // proceed to the next option and return true. + bool MatchAndSet(const char *option, + std::vector<std::pair<std::string, std::string> > *optargs) { + if (token_.compare(option) != 0) { + return false; + } + next(); + while (!AtEnd() && '-' != token_.at(0)) { + size_t commapos = token_.find(','); + if (commapos == std::string::npos) { + optargs->push_back(std::pair<std::string, std::string>(token_, "")); + } else { + std::string first = token_.substr(0, commapos); + token_.erase(0, commapos + 1); + optargs->push_back(std::pair<std::string, std::string>(first, token_)); + } + + next(); + } + return true; + } + // Current token. const std::string &token() const { return token_; } |