mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-28 07:43:11 +08:00
Rename func to keyfunc
This commit is contained in:
parent
c87d063211
commit
1d4d238577
@ -723,14 +723,14 @@ static int path_sort(parser_t &parser, io_streams_t &streams, int argc, const wc
|
|||||||
int retval = parse_opts(&opts, &optind, 0, argc, argv, parser, streams);
|
int retval = parse_opts(&opts, &optind, 0, argc, argv, parser, streams);
|
||||||
if (retval != STATUS_CMD_OK) return retval;
|
if (retval != STATUS_CMD_OK) return retval;
|
||||||
|
|
||||||
auto func = +[] (const wcstring &x) {
|
auto keyfunc = +[] (const wcstring &x) {
|
||||||
return wbasename(x);
|
return wbasename(x);
|
||||||
};
|
};
|
||||||
if (opts.have_key) {
|
if (opts.have_key) {
|
||||||
if (std::wcscmp(opts.key, L"basename") == 0) {
|
if (std::wcscmp(opts.key, L"basename") == 0) {
|
||||||
// Do nothing, this is the default
|
// Do nothing, this is the default
|
||||||
} else if (std::wcscmp(opts.key, L"dirname") == 0) {
|
} else if (std::wcscmp(opts.key, L"dirname") == 0) {
|
||||||
func = +[] (const wcstring &x) {
|
keyfunc = +[] (const wcstring &x) {
|
||||||
return wdirname(x);
|
return wdirname(x);
|
||||||
};
|
};
|
||||||
} else if (std::wcscmp(opts.key, L"path") == 0) {
|
} else if (std::wcscmp(opts.key, L"path") == 0) {
|
||||||
@ -749,10 +749,10 @@ static int path_sort(parser_t &parser, io_streams_t &streams, int argc, const wc
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (opts.have_key) {
|
if (opts.have_key) {
|
||||||
// Keep a map to avoid repeated func calls and to keep things alive.
|
// Keep a map to avoid repeated keyfunc calls and to keep things alive.
|
||||||
std::map<wcstring, wcstring> funced;
|
std::map<wcstring, wcstring> key;
|
||||||
for (const auto &arg : list) {
|
for (const auto &arg : list) {
|
||||||
funced[arg] = func(arg);
|
key[arg] = keyfunc(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We use a stable sort here, and also explicit < and >,
|
// We use a stable sort here, and also explicit < and >,
|
||||||
@ -760,14 +760,14 @@ static int path_sort(parser_t &parser, io_streams_t &streams, int argc, const wc
|
|||||||
std::stable_sort(list.begin(), list.end(),
|
std::stable_sort(list.begin(), list.end(),
|
||||||
[&](const wcstring &a, const wcstring &b) {
|
[&](const wcstring &a, const wcstring &b) {
|
||||||
if (!opts.invert)
|
if (!opts.invert)
|
||||||
return (wcsfilecmp_glob(funced[a].c_str(), funced[b].c_str()) < 0);
|
return (wcsfilecmp_glob(key[a].c_str(), key[b].c_str()) < 0);
|
||||||
else
|
else
|
||||||
return (wcsfilecmp_glob(funced[a].c_str(), funced[b].c_str()) > 0);
|
return (wcsfilecmp_glob(key[a].c_str(), key[b].c_str()) > 0);
|
||||||
});
|
});
|
||||||
if (opts.unique) {
|
if (opts.unique) {
|
||||||
list.erase(std::unique(list.begin(), list.end(),
|
list.erase(std::unique(list.begin(), list.end(),
|
||||||
[&](const wcstring &a, const wcstring &b) {
|
[&](const wcstring &a, const wcstring &b) {
|
||||||
return funced[a] == funced[b];
|
return key[a] == key[b];
|
||||||
}),
|
}),
|
||||||
list.end());
|
list.end());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user