diff options
author | Andreas Kling <kling@serenityos.org> | 2021-06-01 09:01:31 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-01 09:02:43 +0200 |
commit | 313e53dca0a6c13fcf43ef6ad545dc2d34952a0a (patch) | |
tree | aca86f211c479da63ccf7adfd12addb67f8527f4 /Userland/Libraries/LibCore/ArgsParser.cpp | |
parent | dd9b8ee7ef5666b0ba257a40c7c024628f821448 (diff) | |
download | serenity-313e53dca0a6c13fcf43ef6ad545dc2d34952a0a.zip |
LibCore: Add StringView overloads for Core::ArgsParser
These allow you to get StringView wrappers around on-stack string
arguments, which seems pretty nice. :^)
Diffstat (limited to 'Userland/Libraries/LibCore/ArgsParser.cpp')
-rw-r--r-- | Userland/Libraries/LibCore/ArgsParser.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/ArgsParser.cpp b/Userland/Libraries/LibCore/ArgsParser.cpp index 56fa4df5c6..3c8e3597a0 100644 --- a/Userland/Libraries/LibCore/ArgsParser.cpp +++ b/Userland/Libraries/LibCore/ArgsParser.cpp @@ -285,6 +285,22 @@ void ArgsParser::add_option(String& value, const char* help_string, const char* add_option(move(option)); } +void ArgsParser::add_option(StringView& value, char const* help_string, char const* long_name, char short_name, char const* value_name) +{ + Option option { + true, + help_string, + long_name, + short_name, + value_name, + [&value](const char* s) { + value = s; + return true; + } + }; + add_option(move(option)); +} + void ArgsParser::add_option(int& value, const char* help_string, const char* long_name, char short_name, const char* value_name) { Option option { @@ -354,6 +370,21 @@ void ArgsParser::add_positional_argument(String& value, const char* help_string, add_positional_argument(move(arg)); } +void ArgsParser::add_positional_argument(StringView& value, char const* help_string, char const* name, Required required) +{ + Arg arg { + help_string, + name, + required == Required::Yes ? 1 : 0, + 1, + [&value](const char* s) { + value = s; + return true; + } + }; + add_positional_argument(move(arg)); +} + void ArgsParser::add_positional_argument(int& value, const char* help_string, const char* name, Required required) { Arg arg { |