mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-28 01:11:15 -03:00
Give wildcard_expand_result_t a real return value
Use an enum instead of an int.
This commit is contained in:
@@ -1010,15 +1010,18 @@ expand_result_t expander_t::stage_wildcards(wcstring path_to_expand,
|
||||
result = expand_result_t::wildcard_no_match;
|
||||
std::vector<completion_t> expanded;
|
||||
for (const auto &effective_working_dir : effective_working_dirs) {
|
||||
int local_wc_res =
|
||||
wildcard_expand_result_t expand_res =
|
||||
wildcard_expand_string(path_to_expand, effective_working_dir, flags, &expanded);
|
||||
if (local_wc_res > 0) {
|
||||
// Something matched,so overall we matched.
|
||||
result = expand_result_t::wildcard_match;
|
||||
} else if (local_wc_res < 0) {
|
||||
// Cancellation
|
||||
result = expand_result_t::error;
|
||||
break;
|
||||
switch (expand_res) {
|
||||
case wildcard_expand_result_t::match:
|
||||
// Something matched,so overall we matched.
|
||||
result = expand_result_t::wildcard_match;
|
||||
break;
|
||||
case wildcard_expand_result_t::no_match:
|
||||
break;
|
||||
case wildcard_expand_result_t::cancel:
|
||||
result = expand_result_t::error;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -645,11 +645,11 @@ class wildcard_expander_t {
|
||||
// Do wildcard expansion. This is recursive.
|
||||
void expand(const wcstring &base_dir, const wchar_t *wc, const wcstring &prefix);
|
||||
|
||||
int status_code() const {
|
||||
wildcard_expand_result_t status_code() const {
|
||||
if (this->did_interrupt) {
|
||||
return -1;
|
||||
return wildcard_expand_result_t::cancel;
|
||||
}
|
||||
return this->did_add ? 1 : 0;
|
||||
return this->did_add ? wildcard_expand_result_t::match : wildcard_expand_result_t::no_match;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -898,8 +898,10 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc,
|
||||
}
|
||||
}
|
||||
|
||||
int wildcard_expand_string(const wcstring &wc, const wcstring &working_directory,
|
||||
expand_flags_t flags, std::vector<completion_t> *output) {
|
||||
wildcard_expand_result_t wildcard_expand_string(const wcstring &wc,
|
||||
const wcstring &working_directory,
|
||||
expand_flags_t flags,
|
||||
std::vector<completion_t> *output) {
|
||||
assert(output != nullptr);
|
||||
// Fuzzy matching only if we're doing completions.
|
||||
assert(flags.get(expand_flag::for_completions) || !flags.get(expand_flag::fuzzy_match));
|
||||
@@ -916,7 +918,7 @@ int wildcard_expand_string(const wcstring &wc, const wcstring &working_directory
|
||||
// embedded nulls are never allowed in a filename, so we just check for them and return 0 (no
|
||||
// matches) if there is an embedded null.
|
||||
if (wc.find(L'\0') != wcstring::npos) {
|
||||
return 0;
|
||||
return wildcard_expand_result_t::no_match;
|
||||
}
|
||||
|
||||
// Compute the prefix and base dir. The prefix is what we prepend for filesystem operations
|
||||
|
||||
@@ -41,9 +41,15 @@ enum {
|
||||
/// executables_only
|
||||
/// \param out The list in which to put the output
|
||||
///
|
||||
/// \return 1 if matches where found, 0 otherwise. Return -1 on abort (I.e. ^C was pressed).
|
||||
int wildcard_expand_string(const wcstring &wc, const wcstring &working_directory,
|
||||
expand_flags_t flags, std::vector<completion_t> *out);
|
||||
enum class wildcard_expand_result_t {
|
||||
no_match, /// The wildcard did not match.
|
||||
match, /// The wildcard did match.
|
||||
cancel, /// Expansion was cancelled (e.g. control-C).
|
||||
};
|
||||
wildcard_expand_result_t wildcard_expand_string(const wcstring &wc,
|
||||
const wcstring &working_directory,
|
||||
expand_flags_t flags,
|
||||
std::vector<completion_t> *out);
|
||||
|
||||
/// Test whether the given wildcard matches the string. Does not perform any I/O.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user