summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Tests/LibCore/TestLibCoreArgsParser.cpp6
-rw-r--r--Userland/Libraries/LibCore/ArgsParser.cpp15
-rw-r--r--Userland/Libraries/LibCore/ArgsParser.h1
-rw-r--r--Userland/Services/FileOperation/main.cpp14
-rw-r--r--Userland/Utilities/asctl.cpp4
-rw-r--r--Userland/Utilities/cat.cpp2
-rw-r--r--Userland/Utilities/checksum.cpp2
-rw-r--r--Userland/Utilities/cp.cpp2
-rw-r--r--Userland/Utilities/cut.cpp4
-rw-r--r--Userland/Utilities/gunzip.cpp2
-rw-r--r--Userland/Utilities/gzip.cpp6
-rw-r--r--Userland/Utilities/js.cpp2
-rw-r--r--Userland/Utilities/ls.cpp4
-rw-r--r--Userland/Utilities/rev.cpp4
-rw-r--r--Userland/Utilities/sysctl.cpp4
-rw-r--r--Userland/Utilities/tac.cpp4
-rw-r--r--Userland/Utilities/zip.cpp2
17 files changed, 31 insertions, 47 deletions
diff --git a/Tests/LibCore/TestLibCoreArgsParser.cpp b/Tests/LibCore/TestLibCoreArgsParser.cpp
index 753dca8958..b19f0fab81 100644
--- a/Tests/LibCore/TestLibCoreArgsParser.cpp
+++ b/Tests/LibCore/TestLibCoreArgsParser.cpp
@@ -147,7 +147,7 @@ TEST_CASE(positional_string_argument)
TEST_CASE(positional_vector_string_argument)
{
// Zero or more positional arguments, zero given
- Vector<String> values = {};
+ Vector<StringView> values;
auto parser_result = run_parser({ "app" }, [&](auto& parser) {
parser.add_positional_argument(values, "values", "values", Core::ArgsParser::Required::No);
});
@@ -213,7 +213,7 @@ TEST_CASE(combination_of_bool_options_with_positional_vector_string)
// Expected: all arguments fill as given
bool bool_opt1 = false;
bool bool_opt2 = false;
- Vector<String> positionals = {};
+ Vector<StringView> positionals;
auto parser_result = run_parser({ "app", "-b", "-c", "one", "two" }, [&](auto& parser) {
parser.add_option(bool_opt1, "bool_opt1", nullptr, 'b');
parser.add_option(bool_opt2, "bool_opt2", nullptr, 'c');
@@ -318,7 +318,7 @@ TEST_CASE(stop_on_first_non_option)
// Expected: bool options are set and one positional argument is filled
bool bool_opt1 = false;
bool bool_opt2 = false;
- Vector<String> positionals = {};
+ Vector<StringView> positionals;
auto parser_result = run_parser({ "app", "-b", "-c", "one" }, [&](auto& parser) {
parser.set_stop_on_first_non_option(false);
parser.add_option(bool_opt1, "bool_opt1", nullptr, 'b');
diff --git a/Userland/Libraries/LibCore/ArgsParser.cpp b/Userland/Libraries/LibCore/ArgsParser.cpp
index db1ec8d5e7..f37e0a7d9b 100644
--- a/Userland/Libraries/LibCore/ArgsParser.cpp
+++ b/Userland/Libraries/LibCore/ArgsParser.cpp
@@ -580,21 +580,6 @@ void ArgsParser::add_positional_argument(Vector<const char*>& values, const char
add_positional_argument(move(arg));
}
-void ArgsParser::add_positional_argument(Vector<String>& values, const char* help_string, const char* name, Required required)
-{
- Arg arg {
- help_string,
- name,
- required == Required::Yes ? 1 : 0,
- INT_MAX,
- [&values](const char* s) {
- values.append(s);
- return true;
- }
- };
- add_positional_argument(move(arg));
-}
-
void ArgsParser::add_positional_argument(Vector<StringView>& values, char const* help_string, char const* name, Required required)
{
Arg arg {
diff --git a/Userland/Libraries/LibCore/ArgsParser.h b/Userland/Libraries/LibCore/ArgsParser.h
index 9c0998968b..ffeafeb46b 100644
--- a/Userland/Libraries/LibCore/ArgsParser.h
+++ b/Userland/Libraries/LibCore/ArgsParser.h
@@ -86,7 +86,6 @@ public:
void add_positional_argument(unsigned& value, const char* help_string, const char* name, Required required = Required::Yes);
void add_positional_argument(double& value, const char* help_string, const char* name, Required required = Required::Yes);
void add_positional_argument(Vector<const char*>& value, const char* help_string, const char* name, Required required = Required::Yes);
- void add_positional_argument(Vector<String>& value, const char* help_string, const char* name, Required required = Required::Yes);
void add_positional_argument(Vector<StringView>& value, char const* help_string, char const* name, Required required = Required::Yes);
private:
diff --git a/Userland/Services/FileOperation/main.cpp b/Userland/Services/FileOperation/main.cpp
index 5515a3569d..6e174e7471 100644
--- a/Userland/Services/FileOperation/main.cpp
+++ b/Userland/Services/FileOperation/main.cpp
@@ -28,9 +28,9 @@ struct WorkItem {
off_t size;
};
-static int perform_copy(Vector<String> const& sources, String const& destination);
-static int perform_move(Vector<String> const& sources, String const& destination);
-static int perform_delete(Vector<String> const& sources);
+static int perform_copy(Vector<StringView> const& sources, String const& destination);
+static int perform_move(Vector<StringView> const& sources, String const& destination);
+static int perform_delete(Vector<StringView> const& sources);
static int execute_work_items(Vector<WorkItem> const& items);
static void report_error(String message);
static void report_warning(String message);
@@ -40,7 +40,7 @@ static String deduplicate_destination_file_name(String const& destination);
int main(int argc, char** argv)
{
String operation;
- Vector<String> paths;
+ Vector<StringView> paths;
Core::ArgsParser args_parser;
args_parser.add_positional_argument(operation, "Operation: either 'Copy', 'Move' or 'Delete'", "operation", Core::ArgsParser::Required::Yes);
@@ -117,7 +117,7 @@ static bool collect_copy_work_items(String const& source, String const& destinat
return true;
}
-int perform_copy(Vector<String> const& sources, String const& destination)
+int perform_copy(Vector<StringView> const& sources, String const& destination)
{
Vector<WorkItem> items;
@@ -178,7 +178,7 @@ static bool collect_move_work_items(String const& source, String const& destinat
return true;
}
-int perform_move(Vector<String> const& sources, String const& destination)
+int perform_move(Vector<StringView> const& sources, String const& destination)
{
Vector<WorkItem> items;
@@ -228,7 +228,7 @@ static bool collect_delete_work_items(String const& source, Vector<WorkItem>& it
return true;
}
-int perform_delete(Vector<String> const& sources)
+int perform_delete(Vector<StringView> const& sources)
{
Vector<WorkItem> items;
diff --git a/Userland/Utilities/asctl.cpp b/Userland/Utilities/asctl.cpp
index 8d064880d7..28749d5f47 100644
--- a/Userland/Utilities/asctl.cpp
+++ b/Userland/Utilities/asctl.cpp
@@ -30,7 +30,7 @@ int main(int argc, char** argv)
auto audio_client = Audio::ClientConnection::construct();
String command = String::empty();
- Vector<String> arguments;
+ Vector<StringView> arguments;
bool human_mode = false;
Core::ArgsParser args_parser;
@@ -113,7 +113,7 @@ int main(int argc, char** argv)
}
values_to_set.set(AudioVariable::Volume, volume.value());
} else if (variable.is_one_of("m"sv, "mute"sv)) {
- String& mute_text = arguments[++i];
+ auto& mute_text = arguments[++i];
bool mute;
if (mute_text.equals_ignoring_case("true") || mute_text == "1") {
mute = true;
diff --git a/Userland/Utilities/cat.cpp b/Userland/Utilities/cat.cpp
index c749cbeff5..aa9dda6bb8 100644
--- a/Userland/Utilities/cat.cpp
+++ b/Userland/Utilities/cat.cpp
@@ -20,7 +20,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio rpath", nullptr));
- Vector<String> paths;
+ Vector<StringView> paths;
Core::ArgsParser args_parser;
args_parser.set_general_help("Concatenate files or pipes to stdout.");
diff --git a/Userland/Utilities/checksum.cpp b/Userland/Utilities/checksum.cpp
index 254df5bd5a..03971b8b28 100644
--- a/Userland/Utilities/checksum.cpp
+++ b/Userland/Utilities/checksum.cpp
@@ -36,7 +36,7 @@ int main(int argc, char** argv)
auto hash_name = program_name.substring_view(0, program_name.length() - 3).to_string().to_uppercase();
auto paths_help_string = String::formatted("File(s) to print {} checksum of", hash_name);
- Vector<String> paths;
+ Vector<StringView> paths;
Core::ArgsParser args_parser;
args_parser.add_positional_argument(paths, paths_help_string.characters(), "path", Core::ArgsParser::Required::No);
diff --git a/Userland/Utilities/cp.cpp b/Userland/Utilities/cp.cpp
index b5b1cfa668..d6d1fb4599 100644
--- a/Userland/Utilities/cp.cpp
+++ b/Userland/Utilities/cp.cpp
@@ -21,7 +21,7 @@ int main(int argc, char** argv)
bool preserve = false;
bool recursion_allowed = false;
bool verbose = false;
- Vector<String> sources;
+ Vector<StringView> sources;
String destination;
Core::ArgsParser args_parser;
diff --git a/Userland/Utilities/cut.cpp b/Userland/Utilities/cut.cpp
index c50684d103..c035c5b38b 100644
--- a/Userland/Utilities/cut.cpp
+++ b/Userland/Utilities/cut.cpp
@@ -153,7 +153,7 @@ int main(int argc, char** argv)
String fields_list = "";
String delimiter = "\t";
- Vector<String> files;
+ Vector<StringView> files;
Core::ArgsParser args_parser;
args_parser.add_positional_argument(files, "file(s) to cut", "file", Core::ArgsParser::Required::No);
@@ -230,7 +230,7 @@ int main(int argc, char** argv)
for (auto& file : files) {
FILE* fp = stdin;
if (!file.is_null()) {
- fp = fopen(file.characters(), "r");
+ fp = fopen(String(file).characters(), "r");
if (!fp) {
warnln("cut: Could not open file '{}'", file);
continue;
diff --git a/Userland/Utilities/gunzip.cpp b/Userland/Utilities/gunzip.cpp
index 589e0ddd3d..b2743406b4 100644
--- a/Userland/Utilities/gunzip.cpp
+++ b/Userland/Utilities/gunzip.cpp
@@ -25,7 +25,7 @@ static bool decompress_file(Buffered<Core::InputFileStream>& input_stream, Buffe
int main(int argc, char** argv)
{
- Vector<String> filenames;
+ Vector<StringView> filenames;
bool keep_input_files { false };
bool write_to_stdout { false };
diff --git a/Userland/Utilities/gzip.cpp b/Userland/Utilities/gzip.cpp
index 71bf648520..18cefb442a 100644
--- a/Userland/Utilities/gzip.cpp
+++ b/Userland/Utilities/gzip.cpp
@@ -12,7 +12,7 @@
int main(int argc, char** argv)
{
- Vector<String> filenames;
+ Vector<StringView> filenames;
bool keep_input_files { false };
bool write_to_stdout { false };
bool decompress { false };
@@ -34,7 +34,7 @@ int main(int argc, char** argv)
warnln("unknown suffix for: {}, skipping", input_filename);
continue;
}
- output_filename = input_filename.substring(0, input_filename.length() - ".gz"sv.length());
+ output_filename = input_filename.substring_view(0, input_filename.length() - ".gz"sv.length());
} else {
output_filename = String::formatted("{}.gz", input_filename);
}
@@ -78,7 +78,7 @@ int main(int argc, char** argv)
}
if (!keep_input_files) {
- const auto retval = unlink(input_filename.characters());
+ const auto retval = unlink(String(input_filename).characters());
if (retval != 0) {
warnln("Failed removing input file");
return 1;
diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp
index e433be05ac..22bb3675c6 100644
--- a/Userland/Utilities/js.cpp
+++ b/Userland/Utilities/js.cpp
@@ -1163,7 +1163,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
bool gc_on_every_allocation = false;
bool disable_syntax_highlight = false;
- Vector<String> script_paths;
+ Vector<StringView> script_paths;
Core::ArgsParser args_parser;
args_parser.set_general_help("This is a JavaScript interpreter.");
diff --git a/Userland/Utilities/ls.cpp b/Userland/Utilities/ls.cpp
index 8704f5caf3..39614ed889 100644
--- a/Userland/Utilities/ls.cpp
+++ b/Userland/Utilities/ls.cpp
@@ -98,7 +98,7 @@ int main(int argc, char** argv)
return 1;
}
- Vector<String> paths;
+ Vector<StringView> paths;
Core::ArgsParser args_parser;
args_parser.set_general_help("List files in a directory.");
@@ -148,7 +148,7 @@ int main(int argc, char** argv)
FileMetadata metadata;
metadata.name = path;
- int rc = lstat(path.characters(), &metadata.stat);
+ int rc = lstat(String(path).characters(), &metadata.stat);
if (rc < 0)
perror("lstat");
diff --git a/Userland/Utilities/rev.cpp b/Userland/Utilities/rev.cpp
index 5b42754203..5fb4498ad7 100644
--- a/Userland/Utilities/rev.cpp
+++ b/Userland/Utilities/rev.cpp
@@ -16,7 +16,7 @@ int main(int argc, char** argv)
return 1;
}
- Vector<String> paths;
+ Vector<StringView> paths;
Core::ArgsParser args_parser;
args_parser.set_general_help("Concatente files to stdout with each line in reverse.");
@@ -29,7 +29,7 @@ int main(int argc, char** argv)
if (!paths.is_empty()) {
for (auto const& path : paths) {
- FILE* stream = fopen(path.characters(), "r");
+ FILE* stream = fopen(String(path).characters(), "r");
if (!stream) {
warnln("Failed to open {}: {}", path, strerror(errno));
continue;
diff --git a/Userland/Utilities/sysctl.cpp b/Userland/Utilities/sysctl.cpp
index 8d1a357374..f339ddf2f8 100644
--- a/Userland/Utilities/sysctl.cpp
+++ b/Userland/Utilities/sysctl.cpp
@@ -54,7 +54,7 @@ static bool write_variable(StringView name, StringView value)
return true;
}
-static int handle_variables(Vector<String> const& variables)
+static int handle_variables(Vector<StringView> const& variables)
{
bool success = false;
for (auto const& variable : variables) {
@@ -95,7 +95,7 @@ static int handle_show_all()
int main(int argc, char** argv)
{
bool show_all = false;
- Vector<String> variables;
+ Vector<StringView> variables;
Core::ArgsParser args_parser;
args_parser.set_general_help("Show or modify system-internal values. This requires root, and can crash your system.");
diff --git a/Userland/Utilities/tac.cpp b/Userland/Utilities/tac.cpp
index 8568677421..e668115801 100644
--- a/Userland/Utilities/tac.cpp
+++ b/Userland/Utilities/tac.cpp
@@ -16,7 +16,7 @@ int main(int argc, char** argv)
return 1;
}
- Vector<String> paths;
+ Vector<StringView> paths;
Core::ArgsParser args_parser;
args_parser.set_general_help("Concatenate files or pipes to stdout, last line first.");
@@ -33,7 +33,7 @@ int main(int argc, char** argv)
if (path == "-"sv) {
stream = stdin;
} else {
- stream = fopen(path.characters(), "r");
+ stream = fopen(String(path).characters(), "r");
if (!stream) {
warnln("Failed to open {}: {}", path, strerror(errno));
continue;
diff --git a/Userland/Utilities/zip.cpp b/Userland/Utilities/zip.cpp
index 8ecf1b65e4..0f68c8f304 100644
--- a/Userland/Utilities/zip.cpp
+++ b/Userland/Utilities/zip.cpp
@@ -16,7 +16,7 @@
int main(int argc, char** argv)
{
const char* zip_path;
- Vector<String> source_paths;
+ Vector<StringView> source_paths;
bool recurse = false;
bool force = false;