From ed3a5f6b9d23fbac591947eb64f09e96d20a3697 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Tue, 9 Nov 2021 02:06:38 +0100 Subject: [PATCH] Utilities: cut: Move string splitting into expand_list --- Userland/Utilities/cut.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Userland/Utilities/cut.cpp b/Userland/Utilities/cut.cpp index 508fb73f0f..97fa55121f 100644 --- a/Userland/Utilities/cut.cpp +++ b/Userland/Utilities/cut.cpp @@ -50,8 +50,10 @@ static void add_if_not_exists(Vector& indices, Index data) } } -static bool expand_list(Vector& tokens, Vector& indices) +static bool expand_list(String& list, Vector& indices) { + Vector tokens = list.split(','); + for (auto& token : tokens) { if (token.length() == 0) { warnln("cut: byte/character positions are numbered from 1"); @@ -181,7 +183,7 @@ static void cut_file(const String& file, const Vector& byte_vector) int main(int argc, char** argv) { String byte_list = ""; - Vector tokens; + Vector files; Core::ArgsParser args_parser; @@ -195,10 +197,8 @@ int main(int argc, char** argv) return 1; } - tokens = byte_list.split(','); - Vector byte_vector; - auto expansion_successful = expand_list(tokens, byte_vector); + auto expansion_successful = expand_list(byte_list, byte_vector); if (!expansion_successful) { args_parser.print_usage(stderr, argv[0]);