From 23dff4f20921b2970c64a6b16d7c5876fc32ee63 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 16 Jan 2018 10:11:06 +0100 Subject: [PATCH] util/OptionParser: use ConstBuffer to store argv/argc --- src/util/OptionParser.cxx | 4 +--- src/util/OptionParser.hxx | 9 +++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/util/OptionParser.cxx b/src/util/OptionParser.cxx index 4cc1acb16..e51b215f4 100644 --- a/src/util/OptionParser.cxx +++ b/src/util/OptionParser.cxx @@ -40,9 +40,7 @@ bool OptionParser::ParseNext() noexcept { assert(HasEntries()); - const char *arg = *argv; - ++argv; - --argc; + const char *arg = args.shift(); if (arg[0] == '-') { if (arg[1] == '-') { option = arg + 2; diff --git a/src/util/OptionParser.hxx b/src/util/OptionParser.hxx index e8dd5de60..a6169eeeb 100644 --- a/src/util/OptionParser.hxx +++ b/src/util/OptionParser.hxx @@ -20,6 +20,8 @@ #ifndef MPD_UTIL_OPTIONPARSER_HXX #define MPD_UTIL_OPTIONPARSER_HXX +#include "util/ConstBuffer.hxx" + #include class OptionDef; @@ -29,8 +31,7 @@ class OptionDef; */ class OptionParser { - int argc; - char *const*argv; + ConstBuffer args; const char *option = nullptr; const char *option_raw = nullptr; bool is_long = false; @@ -40,13 +41,13 @@ public: * Constructs #OptionParser. */ constexpr OptionParser(int _argc, char *const*_argv) noexcept - :argc(_argc - 1), argv(_argv + 1) {} + :args(_argv + 1, _argc - 1) {} /** * Checks if there are command line entries to process. */ constexpr bool HasEntries() const noexcept { - return argc > 0; + return !args.empty(); } /**