sort: Allow multi-character separators to be given with the -t option

This commit is contained in:
Tim Ledbetter 2023-08-26 23:58:47 +01:00 committed by Tim Flynn
parent e6112446db
commit 94b247ec3c

View file

@ -57,7 +57,7 @@ struct Options {
bool numeric { false };
bool reverse { false };
bool zero_terminated { false };
StringView separator { "\0", 1 };
StringView separator {};
Vector<DeprecatedString> files;
};
@ -72,9 +72,9 @@ static ErrorOr<void> 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 {