Feature flag support for ? wildcard

This partially reverts 6e56637cf0 and #4520
by bringing back the ? wildcard, guarded by the qmark-noglob feature flag.
This commit is contained in:
ridiculousfish
2018-05-05 19:11:57 -07:00
parent dc8d603f98
commit 762c31be87
13 changed files with 117 additions and 41 deletions

View File

@@ -16,6 +16,7 @@
#include "common.h"
#include "expand.h"
#include "fallback.h" // IWYU pragma: keep
#include "future_feature_flags.h"
#include "parse_constants.h"
#include "parse_util.h"
#include "tnode.h"
@@ -418,14 +419,20 @@ void parse_util_token_extent(const wchar_t *buff, size_t cursor_pos, const wchar
wcstring parse_util_unescape_wildcards(const wcstring &str) {
wcstring result;
result.reserve(str.size());
bool unesc_qmark = !fish_features().test(features_t::qmark_noglob);
const wchar_t *const cs = str.c_str();
for (size_t i = 0; cs[i] != L'\0'; i++) {
if (cs[i] == L'*') {
result.push_back(ANY_STRING);
} else if (cs[i] == L'?' && unesc_qmark) {
result.push_back(ANY_CHAR);
} else if (cs[i] == L'\\' && cs[i + 1] == L'*') {
result.push_back(cs[i + 1]);
i += 1;
} else if (cs[i] == L'\\' && cs[i + 1] == L'?' && unesc_qmark) {
result.push_back(cs[i + 1]);
i += 1;
} else if (cs[i] == L'\\' && cs[i + 1] == L'\\') {
// Not a wildcard, but ensure the next iteration doesn't see this escaped backslash.
result.append(L"\\\\");
@@ -890,7 +897,9 @@ void parse_util_expand_variable_error(const wcstring &token, size_t global_token
default: {
wchar_t token_stop_char = char_after_dollar;
// Unescape (see issue #50).
if (token_stop_char == ANY_STRING || token_stop_char == ANY_STRING_RECURSIVE)
if (token_stop_char == ANY_CHAR)
token_stop_char = L'?';
else if (token_stop_char == ANY_STRING || token_stop_char == ANY_STRING_RECURSIVE)
token_stop_char = L'*';
// Determine which error message to use. The format string may not consume all the