diff options
author | Max Kellermann <max@musicpd.org> | 2018-01-16 11:03:04 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-01-16 11:08:23 +0100 |
commit | 68f660dbcce025b2e95e46d193ca69269c56ee69 (patch) | |
tree | 5c057f69a6791dfa1a7ebce13638e78ef95dd61d /src/util | |
parent | 0066f7a818a5e49e53c140ce4da830c3c4f19960 (diff) |
util/OptionParser: collect remaining arguments
Allow the caller to use a simple "for" loop without checking
arguments.
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/OptionParser.cxx | 2 | ||||
-rw-r--r-- | src/util/OptionParser.hxx | 15 |
2 files changed, 11 insertions, 6 deletions
diff --git a/src/util/OptionParser.cxx b/src/util/OptionParser.cxx index e51b215f4..5b7d7fc85 100644 --- a/src/util/OptionParser.cxx +++ b/src/util/OptionParser.cxx @@ -53,7 +53,9 @@ OptionParser::ParseNext() noexcept option_raw = arg; return true; } + option = nullptr; option_raw = nullptr; + *remaining_tail++ = arg; return false; } diff --git a/src/util/OptionParser.hxx b/src/util/OptionParser.hxx index a6169eeeb..84a4f0e4f 100644 --- a/src/util/OptionParser.hxx +++ b/src/util/OptionParser.hxx @@ -36,12 +36,16 @@ class OptionParser const char *option_raw = nullptr; bool is_long = false; + const char **const remaining_head, **remaining_tail; + public: /** * Constructs #OptionParser. */ - constexpr OptionParser(int _argc, char *const*_argv) noexcept - :args(_argv + 1, _argc - 1) {} + constexpr OptionParser(int _argc, char **_argv) noexcept + :args(_argv + 1, _argc - 1), + remaining_head(const_cast<const char **>(_argv + 1)), + remaining_tail(remaining_head) {} /** * Checks if there are command line entries to process. @@ -81,11 +85,10 @@ public: bool ParseNext() noexcept; /** - * Checks if specified string is a command line option. + * Returns the remaining non-option arguments. */ - static bool IsOption(const char *s) noexcept { - assert(s != nullptr); - return s[0] == '-'; + ConstBuffer<const char *> GetRemaining() const noexcept { + return {remaining_head, remaining_tail}; } }; |