[ox/clargs] Add constructor that takes a SpanView
This commit is contained in:
parent
3308b4dd72
commit
edda8e010e
13
deps/ox/src/ox/clargs/clargs.cpp
vendored
13
deps/ox/src/ox/clargs/clargs.cpp
vendored
@ -11,18 +11,19 @@
|
||||
|
||||
namespace ox {
|
||||
|
||||
ClArgs::ClArgs(int argc, const char **args) noexcept {
|
||||
auto const argv = ox::SpanView{args, static_cast<size_t>(argc)};
|
||||
for (auto i = 0u; i < static_cast<unsigned>(argc); ++i) {
|
||||
auto arg = StringView(argv[i]);
|
||||
ClArgs::ClArgs(int argc, const char **args) noexcept: ClArgs({args, static_cast<size_t>(argc)}) {}
|
||||
|
||||
ClArgs::ClArgs(ox::SpanView<const char*> 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<unsigned>(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;
|
||||
|
3
deps/ox/src/ox/clargs/clargs.hpp
vendored
3
deps/ox/src/ox/clargs/clargs.hpp
vendored
@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/hashmap.hpp>
|
||||
#include <ox/std/span.hpp>
|
||||
#include <ox/std/string.hpp>
|
||||
|
||||
namespace ox {
|
||||
@ -22,6 +23,8 @@ class ClArgs {
|
||||
public:
|
||||
ClArgs(int argc, const char **args) noexcept;
|
||||
|
||||
ClArgs(ox::SpanView<const char*> args) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
bool getBool(ox::StringViewCR arg, bool defaultValue) const noexcept;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user