From 94b247ec3ce8b3e2b9743499f5df7f437142bdc9 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sat, 26 Aug 2023 23:58:47 +0100 Subject: [PATCH] sort: Allow multi-character separators to be given with the `-t` option --- Userland/Utilities/sort.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Userland/Utilities/sort.cpp b/Userland/Utilities/sort.cpp index 05e2db6e16..3f058c06c0 100644 --- a/Userland/Utilities/sort.cpp +++ b/Userland/Utilities/sort.cpp @@ -57,7 +57,7 @@ struct Options { bool numeric { false }; bool reverse { false }; bool zero_terminated { false }; - StringView separator { "\0", 1 }; + StringView separator {}; Vector files; }; @@ -72,9 +72,9 @@ static ErrorOr load_file(Options const& options, StringView filename, Stri DeprecatedString line { TRY(file->read_until(buffer, line_delimiter)) }; StringView key = line; if (options.key_field != 0) { - auto split = (options.separator[0]) - ? line.split_view(options.separator[0]) - : line.split_view(is_ascii_space); + auto split = (!options.separator.is_empty()) + ? key.split_view(options.separator) + : key.split_view_if(is_ascii_space); if (options.key_field - 1 >= split.size()) { key = ""sv; } else {