mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:17:35 +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
|
@ -44,10 +44,10 @@ ErrorOr<int> serenity_main(Main::Arguments main_arguments)
|
|||
|
||||
StringView placeholder;
|
||||
bool split_with_nulls = false;
|
||||
char const* specified_delimiter = "\n";
|
||||
DeprecatedString specified_delimiter = "\n"sv;
|
||||
Vector<DeprecatedString> arguments;
|
||||
bool verbose = false;
|
||||
char const* file_to_read = "-";
|
||||
DeprecatedString file_to_read = "-"sv;
|
||||
int max_lines_for_one_command = 0;
|
||||
int max_bytes_for_one_command = ARG_MAX;
|
||||
|
||||
|
@ -67,12 +67,12 @@ ErrorOr<int> serenity_main(Main::Arguments main_arguments)
|
|||
size_t max_bytes = min(ARG_MAX, max_bytes_for_one_command);
|
||||
size_t max_lines = max(max_lines_for_one_command, 0);
|
||||
|
||||
if (!split_with_nulls && strlen(specified_delimiter) > 1) {
|
||||
if (!split_with_nulls && specified_delimiter.length() > 1) {
|
||||
warnln("xargs: the delimiter must be a single byte");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char entry_separator = split_with_nulls ? '\0' : *specified_delimiter;
|
||||
char entry_separator = split_with_nulls ? '\0' : specified_delimiter[0];
|
||||
|
||||
if (!placeholder.is_empty())
|
||||
max_lines = 1;
|
||||
|
@ -87,7 +87,7 @@ ErrorOr<int> serenity_main(Main::Arguments main_arguments)
|
|||
|
||||
if ("-"sv != file_to_read) {
|
||||
// A file was specified, try to open it.
|
||||
fp = fopen(file_to_read, "re");
|
||||
fp = fopen(file_to_read.characters(), "re");
|
||||
if (!fp) {
|
||||
perror("fopen");
|
||||
return 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue