mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibCore: Make ArgsParser tolerate Main::Arguments with only .strings
This currently allocates in .parse(), but that's better than making the caller do the exact same before passing us the values. Note that this is only temporary to aid in conversion, a future commit will remove this and switch to requiring the users to allocate the vector instead.
This commit is contained in:
parent
d575c50f3e
commit
6e5ba82929
Notes:
sideshowbarker
2024-07-18 04:38:32 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/6e5ba82929 Pull-request: https://github.com/SerenityOS/serenity/pull/17538 Reviewed-by: https://github.com/ADKaster
1 changed files with 13 additions and 0 deletions
|
@ -73,6 +73,19 @@ public:
|
|||
bool parse(int argc, char* const* argv, FailureBehavior failure_behavior = FailureBehavior::PrintUsageAndExit);
|
||||
bool parse(Main::Arguments const& arguments, FailureBehavior failure_behavior = FailureBehavior::PrintUsageAndExit)
|
||||
{
|
||||
if (arguments.argv == nullptr && arguments.argc == 0) {
|
||||
// Allocate the data from arguments.strings instead.
|
||||
Vector<DeprecatedString> strings;
|
||||
Vector<char const*> data;
|
||||
strings.ensure_capacity(arguments.strings.size());
|
||||
data.ensure_capacity(arguments.strings.size());
|
||||
for (auto& entry : arguments.strings) {
|
||||
strings.append(entry);
|
||||
data.append(strings.last().characters());
|
||||
}
|
||||
return parse(data.size(), const_cast<char* const*>(data.data()), failure_behavior);
|
||||
}
|
||||
|
||||
return parse(arguments.argc, arguments.argv, failure_behavior);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue