From edda8e010edfade07ac059bc2bfd50aeb03fda64 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 28 Nov 2024 00:51:02 -0600 Subject: [PATCH] [ox/clargs] Add constructor that takes a SpanView --- deps/ox/src/ox/clargs/clargs.cpp | 13 +++++++------ deps/ox/src/ox/clargs/clargs.hpp | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/deps/ox/src/ox/clargs/clargs.cpp b/deps/ox/src/ox/clargs/clargs.cpp index cc615379..941d25f6 100644 --- a/deps/ox/src/ox/clargs/clargs.cpp +++ b/deps/ox/src/ox/clargs/clargs.cpp @@ -11,18 +11,19 @@ namespace ox { -ClArgs::ClArgs(int argc, const char **args) noexcept { - auto const argv = ox::SpanView{args, static_cast(argc)}; - for (auto i = 0u; i < static_cast(argc); ++i) { - auto arg = StringView(argv[i]); +ClArgs::ClArgs(int argc, const char **args) noexcept: ClArgs({args, static_cast(argc)}) {} + +ClArgs::ClArgs(ox::SpanView args) noexcept { + for (auto i = 0u; i < args.size(); ++i) { + auto arg = StringView(args[i]); if (arg[0] == '-') { while (arg[0] == '-' && arg.len()) { arg = substr(arg, 1); } m_bools[arg] = true; // parse additional arguments - if (i < static_cast(argc) && argv[i + 1]) { - auto val = String(argv[i + 1]); + if (i < args.size() && args[i + 1]) { + auto val = String(args[i + 1]); if (val.len() && val[i] != '-') { if (val == "false") { m_bools[arg] = false; diff --git a/deps/ox/src/ox/clargs/clargs.hpp b/deps/ox/src/ox/clargs/clargs.hpp index 610d6259..ee54b4a3 100644 --- a/deps/ox/src/ox/clargs/clargs.hpp +++ b/deps/ox/src/ox/clargs/clargs.hpp @@ -9,6 +9,7 @@ #pragma once #include +#include #include namespace ox { @@ -22,6 +23,8 @@ class ClArgs { public: ClArgs(int argc, const char **args) noexcept; + ClArgs(ox::SpanView args) noexcept; + [[nodiscard]] bool getBool(ox::StringViewCR arg, bool defaultValue) const noexcept;