mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 09:27:45 +00:00
LibCore+Everywhere: Remove ArgsParser::add*(char const*&)
This is not guaranteed to always work correctly as ArgsParser deals in StringViews and might have a non-properly-null-terminated string as a value. As a bonus, using StringView (and DeprecatedString where necessary) leads to nicer looking code too :^)
This commit is contained in:
parent
60908adcbe
commit
500044906d
43 changed files with 122 additions and 145 deletions
|
@ -406,24 +406,6 @@ void ArgsParser::add_option(bool& value, char const* help_string, char const* lo
|
|||
add_option(move(option));
|
||||
}
|
||||
|
||||
void ArgsParser::add_option(char const*& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode)
|
||||
{
|
||||
Option option {
|
||||
OptionArgumentMode::Required,
|
||||
help_string,
|
||||
long_name,
|
||||
short_name,
|
||||
value_name,
|
||||
[&value](StringView s) {
|
||||
VERIFY(s.length() == strlen(s.characters_without_null_termination()));
|
||||
value = s.characters_without_null_termination();
|
||||
return true;
|
||||
},
|
||||
hide_mode,
|
||||
};
|
||||
add_option(move(option));
|
||||
}
|
||||
|
||||
void ArgsParser::add_option(DeprecatedString& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode)
|
||||
{
|
||||
Option option {
|
||||
|
@ -589,22 +571,6 @@ void ArgsParser::add_positional_argument(Arg&& arg)
|
|||
m_positional_args.append(move(arg));
|
||||
}
|
||||
|
||||
void ArgsParser::add_positional_argument(char const*& value, char const* help_string, char const* name, Required required)
|
||||
{
|
||||
Arg arg {
|
||||
help_string,
|
||||
name,
|
||||
required == Required::Yes ? 1 : 0,
|
||||
1,
|
||||
[&value](StringView s) {
|
||||
VERIFY(s.length() == strlen(s.characters_without_null_termination()));
|
||||
value = s.characters_without_null_termination();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
add_positional_argument(move(arg));
|
||||
}
|
||||
|
||||
void ArgsParser::add_positional_argument(DeprecatedString& value, char const* help_string, char const* name, Required required)
|
||||
{
|
||||
Arg arg {
|
||||
|
|
|
@ -87,7 +87,6 @@ public:
|
|||
void add_option(Option&&);
|
||||
void add_ignored(char const* long_name, char short_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||
void add_option(bool& value, char const* help_string, char const* long_name, char short_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||
void add_option(char const*& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||
void add_option(DeprecatedString& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||
void add_option(StringView& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||
template<Integral I>
|
||||
|
@ -101,7 +100,6 @@ public:
|
|||
void add_option(Vector<DeprecatedString>& values, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||
|
||||
void add_positional_argument(Arg&&);
|
||||
void add_positional_argument(char const*& value, char const* help_string, char const* name, Required required = Required::Yes);
|
||||
void add_positional_argument(DeprecatedString& value, char const* help_string, char const* name, Required required = Required::Yes);
|
||||
void add_positional_argument(StringView& value, char const* help_string, char const* name, Required required = Required::Yes);
|
||||
void add_positional_argument(int& value, char const* help_string, char const* name, Required required = Required::Yes);
|
||||
|
|
|
@ -94,7 +94,7 @@ int main(int argc, char** argv)
|
|||
#endif
|
||||
bool print_json = false;
|
||||
bool per_file = false;
|
||||
char const* specified_test_root = nullptr;
|
||||
StringView specified_test_root;
|
||||
DeprecatedString common_path;
|
||||
DeprecatedString test_glob;
|
||||
|
||||
|
@ -143,7 +143,7 @@ int main(int argc, char** argv)
|
|||
|
||||
DeprecatedString test_root;
|
||||
|
||||
if (specified_test_root) {
|
||||
if (!specified_test_root.is_empty()) {
|
||||
test_root = DeprecatedString { specified_test_root };
|
||||
} else {
|
||||
#ifdef AK_OS_SERENITY
|
||||
|
|
|
@ -65,7 +65,7 @@ int TestSuite::main(DeprecatedString const& suite_name, Span<StringView> argumen
|
|||
bool do_tests_only = getenv("TESTS_ONLY") != nullptr;
|
||||
bool do_benchmarks_only = false;
|
||||
bool do_list_cases = false;
|
||||
char const* search_string = "*";
|
||||
StringView search_string = "*"sv;
|
||||
|
||||
args_parser.add_option(do_tests_only, "Only run tests.", "tests", 0);
|
||||
args_parser.add_option(do_benchmarks_only, "Only run benchmarks.", "bench", 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue